此代码正常运行,但有时会选择一行并保存变量,有时不会。
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的所有选项都是默认的
答案 0 :(得分:0)
如果对网格的列进行排序,可能会丢失其索引。试试这个:
string yourVariable = dataGridView1.CurrentRow.Cells[0].Value.ToString();