You can select single or multiple rows in the grid with Row.Selected property and Grid.Selection.Enabled / Grid.Selection.MultipleEnabled property. All selected lines are added to Grid.Selection that supports iteration. To unselect all rows, call Grid.Selection.Clear() method. Please see an example of working with selection below.
C# | Copy |
---|---|
public void ExampleSelection(Grid grid) { //Set a new color for the selected rows which will be blended with the backgroung color of those rows //The grid also supports the alpha-channel. 255 - opaque, 0 - transparent grid.Selection.Color = Color.FromArgb(80, 102, 36, 10); //Allow selection in the grid grid.Selection.Enabled = true; //Allow multiple selection in the grid grid.Selection.MultipleEnabled = true; //Ask the grid to sort selected rows grid.Selection.Sorted = true; //Select the 5th row grid.Rows[5].Selected = true; //Enumerate the selected rows... foreach (Row row in grid.Selection) { //Do something here... } //Clear the selection grid.Selection.Clear(); } |
Back to .Net Grid HowTo topics