Madhana Kumar Madhana Kumar - 9 days ago 9
C# Question

Error in DataGridview.CellContentClick

I am handling cell content click event.
When user clicks the content of a cell it captures accurately.

Consider the case, where I have DataGridViewLinkColumn at column 3
But after clicking a cell ( say row 1 column 3), when the user accidently clicks at any of the table Header,cellclick event is retained i.e. it calls CellContentClicked event with same RowIndex and ColumnIndex(row 1 and column 3).

How to avoid this?
Pls help..

Answer

I have found the answer.. On clicking the table header, cell click is fired for previous selected cell.

We can limit this functionality by adding the condition,

if(e.CoumnIndex>=0 && e.RowIndex >=0)

{

// Add  Logic neccessary for Cell Click event

}

(As rowIndex is -1 for Header row)

Comments