Reputation: 285
I'm looking for a way to deselect a selected DataGridViewRow when the user clicks on it. I have tried fiddling with the various click events of the DataGridView class, but the problem is that the SelectionChanged is fired before these, which causes obvious unintended behavior when the user is clicking a row not selected.
How can I obtain the behvior I want?
Upvotes: 0
Views: 614
Reputation: 9134
It sounds like you are try the alter standard windows select multiple object behaviour. I.e., allowing multi-select then deselecting a given row by clicking on the selected row that you want to deselect. Since the datagrid will fight you tooth and nail in trying to do this based on the standard event handling, you could handle the click event, and use mouse events to determine where they click, etc ... but this is messy and fragile.
I would recommend either teaching standard windows selection behaviour to your users or adding a "selected" column that contains a checkbox and interpreting the "truthiness" of the checkbox value column in further processing.
Upvotes: 1
Reputation: 8475
Set DataGrid.SelectedIndex = -1
in your selectionchanged event, if it was previously selected (that logic is not included here).
Upvotes: 0