CellContentClick event doesn't always work

匿名 (未验证) 提交于 2019-12-03 08:36:05

问题:

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(); } 

回答1:

Try using the CellClick event instead:

Occurs when any part of a cell is clicked.

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!