To select one or more rows in code, you can add (or remove) rows from grid's SelectedRows property. Any row can be selected and added to the grid's collection of SelectedRows as long as its CanBeSelected property is set to true.
Keep in mind that the current row is not the same thing as the selected row and that the current row might not be part of the grid's selected rows. To learn how to change the current row, jump to the How to change the current row topic.
The following example demonstrates how to select a row via code.
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|