CellContentClick
事件并不总是有效 - 它有时有效,有时无效,这是随机的。
我的代码在下面,我正在使用断点进行检查,但程序有时会进入 block ,有时不会。为什么会这样?
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
textBoxUserName.ReadOnly = true;
button2.Visible = true;
int index = e.RowIndex;
if (!(index < 0))
{
DataGridViewRow row = dataGridView1.Rows[index];
textBoxUserName.Text = row.Cells["UserNAme"].Value.ToString();
textBoxPassword.Text = row.Cells["Pass"].Value.ToString();
dataGridView1.Focus();
}
dataGridView1.Focus();
}
最佳答案
尝试使用 CellClick事件代替:
Occurs when any part of a cell is clicked.
CellContentClick单击单元格时不一定会触发事件,用户必须单击单元格的“内容”区域,例如文本,例如:
Occurs when the content within a cell is clicked.
关于c# - CellContentClick 事件并不总是有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22489156/