你好!
我的项目中有一个要求,就是如果我点击datagridviewcell,它应该将值弹出到表单中的文本框中。实际上,有时它能够工作,有时它不能工作,我不知道我做错了什么,就像第三次点击时它就无法工作了。我使用的代码如下:
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int i = dataGridView2.SelectedCells[0].RowIndex;
txtPrjNmae.Text = dataGridView2.Rows[i].Cells[0].Value.ToString();
txtPrjdescription.Text = dataGridView2.Rows[i].Cells[1].Value.ToString();
txtPrjDate.Text = dataGridView2.Rows[i].Cells[2].Value.ToString();
txtPrjSize.Text = dataGridView2.Rows[i].Cells[3].Value.ToString();
txtPrjManager.Text = dataGridView2.Rows[i].Cells[4].Value.ToString();
}
e.RowIndex
而是使用dataGridView2.SelectedCells[0].RowIndex
? - Manish Mishra