Reputation: 1535
I'm using C# ASP.NET VS2010.
I have a GridView including a select command button.
This select button points to an action in the code behind C# page activated upon selection.
After performing all required action I would like to clear the selection.
For example: in case the ID="gvInfo" I would like to use something like gvInfo.Deselect();
How do I do that?
Upvotes: 21
Views: 38028
Reputation:
As explained in https://social.msdn.microsoft.com/Forums/en-US/8a4937d1-531a-49d7-9392-bb76cb9bfcb7/how-to-clear-selectedrow-in-a-gridview?forum=aspwebformsdata —
Gridview has a property called SelectedIndex. If you want to unselect any rows then set this property to -1.
Upvotes: 41
Reputation: 14075
In desktop apps with DataGridView
there is no SelectedIndex
:
gridView1.ClearSelection();
Upvotes: 6
Reputation: 299
I did it this way and it works perfectly.
gridViewName.GetSelectionModel().ClearSelection();
I hope it can work for someone.
Upvotes: 0