Blazor | ComponentOne
Controls / FlexGrid / Cells / Selecting Cells
In This Topic
    Selecting Cells
    In This Topic

    The GridSelectionMode enumeration of the FlexGrid allows you to define the selection mode of the cells by setting its value to Row, Cell, CellRange, RowRange, or None.

    FlexGrid supports single row and cell selection modes, and also row and cell ranges using the shift key. The selected cell data can then be easily retrieved through the SelectedItem property. The images below shows how the FlexGrid appears with different cell selection modes.

    Selection Mode Image Description
    Cell Selection

    Single Cell Selection

    Single Cell Selection

    Cell selection allows you to select a single cell and perform data operations like copy, paste, print etc.
    CellRange Selection
    Cell Range Selection

    Cell Range Selection

    Cell range selection allows you to select multiple cells using the mouse while holding Shift key.
    Row Selection
    Single Row Selection

    Single Row Selection

    Row selection option allows you to select a single row from the grid and perform operations.
    RowRange Selection
    Row Range Selection

    Row Range Selection

    RowRange selection allows you to select multiple rows using the mouse while holding Shift key.

    The following code example demonstrates how to choose selection modes in FlexGrid.

    Razor
    Copy Code
    @page "/FlexGrid/SelectionModes"
    @using Localization
    @using System.Collections.ObjectModel;
    @using C1.Blazor.Grid
    @using C1.Blazor.Input
    @selectedCells
    <FlexGrid ItemsSource="@customers" StyleKind="@GridStyle.Classic" SelectionChanged="OnSelectionChanged" SelectionMode="selectionMode" Style="@("max-height:50vh")" />
    @code {
        ObservableCollection<Customer> customers;
        string selectedCells;
        GridSelectionMode selectionMode = GridSelectionMode.RowRange;
        GridSelectionMode[] selectionModes = new GridSelectionMode[] { GridSelectionMode.None, GridSelectionMode.Cell, GridSelectionMode.CellRange, GridSelectionMode.Row, GridSelectionMode.RowRange };
        protected override void OnInitialized()
        {
            customers = Customer.GetCustomerList(100);
        }
        private void OnSelectionChanged(object sender, GridCellRangeEventArgs e)
        {
            if (e.CellRange != null && e.CellRange.Row != -1)
            {
                int rowsSelected = Math.Abs(e.CellRange.Row2 - e.CellRange.Row) + 1;
                int colsSelected = Math.Abs(e.CellRange.Column2 - e.CellRange.Column) + 1;
                selectedCells = (rowsSelected * colsSelected).ToString() + " " + FlexGridRes.CellsSelectedText;
                StateHasChanged();
            }
        }
    }