Detect key or key combination in Flexgrid

Posted by: piero.albino on 25 February 2025, 12:35 pm EST

    • Post Options:
    • Link

    Posted 25 February 2025, 12:35 pm EST

    Hi,

    Is there a way to directly detects the keys or keys combination on the flexgrid component.

    I would to define a specific method of row deletion on the grid (cell as selectionmode) when selecting a cell and pressing "delete " key or the shortcut “shift+delete”.

    I tried to detect it by using the “onkeyDown” event in a parent div, but it conflict with the cell edition (even in the new row) of the flexgrid.

    I attached the sample project.

    Best Regards,

    Piero

    C1Proyect_TestCase_DelKeyCase.zip

  • Posted 26 February 2025, 12:46 am EST

    Hi,

    Based on my understanding, you want to handle the “Delete” key on the FlexGrid and want to clear out the row value when user presses “Delete” key.

    You could achieve the same by overriding the “OnKeyDown” method of the GridCellFactory. Refer to the following code:

            protected override bool OnKeyDown(KeyboardEventArgs e)
            {
                // Detect the Delete Key
                if(e.Key == "Delete") {
                    // Clear Out the Row Value
                    Grid.SetCellValue(new GridCellRange(Grid.CursorRange.Row, 0, Grid.CursorRange.Row, Grid.Columns.Count - 1), null);
                }
                return base.OnKeyDown(e);
            }

    I have attached the modified sample for your reference. Let me know if you face any issues.

    References:

    GridCellFactory Class: https://developer.mescius.com/componentone/docs/blazor/online-blazor/C1.Blazor.Grid~C1.Blazor.Grid.GridCellFactory.html

    SetCellValue method: https://developer.mescius.com/componentone/docs/blazor/online-blazor/C1.Blazor.Grid~C1.Blazor.Grid.FlexGrid~SetCellValue.html

    Regards,

    Ankit

    C1Proyect_TestCase_DelKeyCase.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels