Reputation: 68
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..
Upvotes: 0
Views: 1677
Reputation: 68
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)
Upvotes: 1
Reputation: 1147
For Windows Form Applications,
if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
{
// Add Logic for Cell Click event
}
else
{
MessageBox.Show("Error Message", "My Application",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
Upvotes: 0
Reputation: 13574
Well this basically happens because of last/default selected row. To get around this problem, you can either define your control with default selection property set to none.
Like in case of a listview, I am using this :
<ListView ItemContainerStyle="{StaticResource listViewStyle}" SelectedIndex=-1 .. />
Upvotes: 0