Using the C1FlexGrid Control > Cell Selection |
The grid has a cursor cell, which displays a focus rectangle while the grid is active. The user may move the cursor with the keyboard or the mouse, and edit the contents of the cell if the grid is editable.
Notice that the Office Visual Styles also indicate the location of the cursor cell by highlighting the row and column headers of the cursor cell's position. For more information about setting the Visual Style, see Customizing Appearance Using Visual Styles.
You can get or set the current cell in code using the Row and Col properties. Setting either of these properties to –1 hides the cursor.
The grid supports extended selections, rectangular ranges of cells defined by two opposing corners: the cursor cell and the cell selection cell.
Notice that the Office Visual Styles also indicate the location of the extended selection by highlighting the row and column headers of the selected cells. For more information about setting the Visual Style, see Customizing Appearance Using Visual Styles.
You can get or set the selection cell in code using the RowSel and ColSel properties, or by using the Select method.
Note: When the cursor cell changes, the selection is automatically reset. To create extended selections in code, either set Row and Col before RowSel and ColSel, or use the Select method. |
The type of selection available is determined by the SelectionMode property. By default, the grid supports regular range selections. You can modify this behavior to prevent extended selections, to select by row, by column, or in listbox mode (listbox mode allows you to select individual rows).
When using the listbox selection mode, you can get or set the selection status for individual rows using the Selected property. You can also retrieve a collection of selected rows using the Selected property. For example, the code below selects all rows that satisfy a condition:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
'Selects all rows with more than 8000 sales in the Sales column. _flex.SelectionMode = C1.Win.C1FlexGrid.SelectionModeEnum.ListBox Dim index As Integer For index = _flex.Rows.Fixed To _flex.Rows.Count - 1 If Val(_flex(index, "Sales")) > 80000 Then _flex.Rows(index).Selected = True End If Next Console.WriteLine("There are now {0} rows selected", _flex.Rows.Selected.Count) |
To write code in C#
C# |
Copy Code
|
---|---|
// Selects all rows with more than 8000 sales in the Sales column. _flex.SelectionMode = SelectionModeEnum.ListBox; for (int index = _flex.Rows.Fixed ; index < _flex.Rows.Count; index++) { if (Microsoft.VisualBasic.Conversion.Val(System.Runtime.CompilerServices.RuntimeHelpers.GetObjectValue(_flex[index, "Sales"])) > 80000) { _flex.Rows[index].Selected = true; } } Console.WriteLine("There are now {0} rows selected", _flex.Rows.Selected.Count); |