【问题标题】:Using LINQ to get DataGridView row value where third column has specific value使用 LINQ 获取第三列具有特定值的 DataGridView 行值
【发布时间】:2015-02-22 23:18:01
【问题描述】:

我想从 DataGridViewRow 中获取单元格的值,其中第三列的值匹配。

但是 System.ArgumentOutOfRangeException 类型的异常“索引超出范围。必须为非负数且小于集合的大小。”已经发生了。

我的代码如下:

 for (int i = 0; i <= intranumber; i++)
        {    
           string source = (string)(from r in dataGridView5.Rows.Cast<DataGridViewRow>()  
                             where   (string)r.Cells[3].Value== intra[i].Item1
                             select r.Cells[1].Value.ToString()).First();

【问题讨论】:

  • 第三列应该被索引2访问:r.Cells[2]
  • 不,这是第四列..我错了
  • 你正在计数,包括intranumber。你确定你不想算不包括:for (int i = 0; i &lt; intranumber; i++)
  • 不,没关系,因为我有一些处理与循环有关.. 问题出在: where (string)r.Cells[3].Value== intra[i].Item1

标签: c# linq datagridview


【解决方案1】:

我认为你的问题是内部[i]。 如果intranumber 是intra.count。所以你必须有我

【讨论】:

  • 没有内部是两个字符串参数的列表
  • 所以你 i = 0 或 i =1 。在你的情况下,我认为内部编号是 >1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-16
相关资源
最近更新 更多