Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 views
in Technique[技术] by (71.8m points)

c# - CellContentClick event doesn't always work

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();
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...