Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataGridView click event doesn't always fire

I have a DataGridView. Its Cell_Content_Click is not firing each time I select a cell. It does fires but not at each click.

I want to get content of selected cell in my string variable 'selected'. Here is what I am doing:

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
    {
        selected = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
    }
}
like image 259
Muhammad Waseem Avatar asked Dec 26 '22 02:12

Muhammad Waseem


1 Answers

The CellContentClick event only fires when the content (text) inside a cell is clicked.

Use the CellClick event instead of CellContentClick, since that event fires when any part of the cell is clicked (not just the content inside it).

like image 188
Grant Winney Avatar answered Jan 05 '23 17:01

Grant Winney