ComponentOne FlexGrid for WinForms
In This Topic
    Cell Selection
    In This Topic

    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.


    The image showing cursor cell in FlexGrid control.

    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 of C1FlexGridBase class. 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.


    The image showing extended selections in FlexGrid control.

    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 of C1FlexGridBase class, 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 appearance of the selection is controlled by the following properties:

    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);
    
    Note: WinForms .NET 5 Edition has only runtime assemblies. Due to the new design-time model in VS2019 Preview, which is not complete yet from the Microsoft side, we do not supply any special design-time features as of yet. However, some of the controls might show up at design-time and allow editing few properties in the property grid.
    See Also