我正在尝试获取所单击行的单元格值。
以下是我的代码:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
txtFullName.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
txtUsername.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
txtPassword.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
}
运行良好...但当我点击行(UserID左侧)和用户ID列时,它无法正常工作...当我点击列标题时也会出现错误。如何修复该错误,我希望能够在行和用户ID列上进行点击。
Cells[0]
是用户ID,对吗?Cells[1]
应该是全名? - Ben