We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Disable deselecting rows by using Escape key

Hi,

I need to disable deselecting rows by Esc key.  Can you help to achieve this please?

- I tried to prevent Esc usage by onkeydown eventhandler of treegrid but RowDeselecting is fired before onkeydown so it does not help.

- I tried to cancel RowDeselecting event (args.Cancel = true) when args.IsInteracted is true but args.Event is null (triggered by interaction but not by mouse event), it seems to cancel but I think the data is stored at backend because after using Escape key if I deselect by mouse click, then all rows get cleared again.

Best Regards


1 Reply

PS Pon Selva Jeganathan Syncfusion Team April 7, 2023 05:53 AM UTC

Hi Yunus,


Query: I need to disable deselecting rows by Esc key.  Can you help to achieve this please? . after using Escape key if I deselect by mouse click, then all rows get cleared again.


Based on your query, we understand that you want to disable the deselection of rows using the Escape key and maintaining the row selection on mouse click. When a row is deselected using the mouse click, all selected rows will be cleared, which is the behavior.


We have achieved this requirement by using the checkbox selection feature of the treegrid and preventing row deselection(while pressing Esc Key) using the RowDeselecting event of the treegrid.


Please refer to the below code snippet,


  <SfTreeGrid DataSource="TreeData" IdMapping="TaskID" ParentIdMapping="ParentID" TreeColumnIndex="2" Height="326">

                <TreeGridSelectionSettings PersistSelection="true" CheckboxOnly="true"></TreeGridSelectionSettings>

                <TreeGridEvents RowDeselecting="rowdeselecting" TValue="SelfReferenceData"></TreeGridEvents>

 

                <TreeGridColumns>

                    <TreeGridColumn Type="Syncfusion.Blazor.Grids.ColumnType.CheckBox" Width="50"></TreeGridColumn>

                </TreeGridColumns>

            </SfTreeGrid>

 

 

 

public void rowdeselecting(RowDeselectEventArgs<SelfReferenceData> args)

    {

        if (args.Event == null )

        {

           

            args.Cancel = true;

        }


Please refer to the below demo,

https://blazor.syncfusion.com/demos/tree-grid/checkbox-selection?theme=bootstrap5


Please refer to the below help documentation,

https://blazor.syncfusion.com/documentation/treegrid/selection#checkbox-selection


Kindly get back to us for further assistance.


Regards,

Pon selva


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.





Loader.
Live Chat Icon For mobile
Up arrow icon