数据网格视图行选择和变量保存奇怪的问题
本文关键字:保存 问题 变量 网格 数据网 视图 行选 选择 数据 | 更新日期: 2023-09-27 18:31:07
这段代码可以工作,但有时选择一行并保存变量,而不是保存变量。
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int Index = 0;
if (e.RowIndex >= 0)
{
Index = e.RowIndex;
dataGridView1.Rows[Index].Selected = true;
DataGridViewRow row = this.dataGridView1.Rows[Index];
nazev = row.Cells[0].Value.ToString();
}
}
DataGridView 的所有选项都是默认的
如果你对网格的列进行排序,也许它会丢失他的索引。试试这个:
string yourVariable = dataGridView1.CurrentRow.Cells[0].Value.ToString();