CellContentClick事件并不总是有效 [英] CellContentClick event doesn't always work
问题描述
CellContentClick
事件并不总是有效-它有时有效,有时不是随机产生的.
CellContentClick
event doesn't always work - it sometimes works and sometimes not, randomly.
我的代码在下面,我正在使用断点进行检查,但是程序有时会进入该块,有时却不会.为什么会这样?
My code is below, I am checking by using breakpoints but program sometimes enters the block and and some times not. Why is it so?
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();
}
推荐答案
尝试使用 在单元格的任何部分被单击时发生.
Occurs when any part of a cell is clicked. CellContentClick 单击单元格时不一定会触发事件,用户必须单击单元格的内容"区域,例如文本,例如: The CellContentClick event won't necessarily fire when you click in the cell, the user has to click into the "content" area of the cell, like the text, for instance: 在单击单元格中的内容时发生. Occurs when the content within a cell is clicked. 这篇关于CellContentClick事件并不总是有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!