【发布时间】:2012-09-07 09:06:05
【问题描述】:
我有如下表
这些是我正在尝试做的代码,但没有希望,我想获得 CAid014 值
string splitter = dataGridView1.Rows[dataGridView1.RowCount].Cells[0].ToString();
MessageBox.Show(splitter); // to print what splitter got
我正在使用 datagridview1.rowcount,因此 datagridview1.rows 将获得最后一行。并且单元格[0] 将获得行的 0 索引并且它得到了错误。
我如何获得 CAid 单元格?
已解决:我想念这样的价值
string splitter = dataGridView1.Rows[dataGridView1.RowCount].Cells[0].value.ToString();
【问题讨论】:
-
你试过
dataGridView1.Rows[dataGridView1.RowCount - 1]?? -
@yogi 是的,我做到了,mbox 没有显示 CAid014
-
@Anonymous 我想获得 CAid014。如果我使用单元格 [0] 是否正确?
-
@nencor:- 看看你是否使用 Rows 它将返回 Row 集合,因此添加 [X] 将指向集合中的第 X 个索引。所以 cells[0] 显然返回第一个单元格的内容在最后一行。所以最好使用 String.Format("{0}",dataGridView1.Rows[dataGridView1.RowCount-1].Cells[0].Value)。也许还有 value2 属性我几乎不记得了;你可以试试
-
@nencor 如果我们帮助你,你应该接受一个答案
标签: c# datagridview rows cells