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 KeyBoard commands

Hi

how to disable any keyboard command or specifically the delete key

Regards



2 Replies

SA Salvatore December 22, 2022 10:07 AM UTC

Hello

I wanted to communicate that the solution to my problem lies in the constraints that can be set in the various nodes, connectors and so on.

thanks anyway



SU Sumathi Uthayakumar Syncfusion Team December 22, 2022 02:26 PM UTC


Hi Salvatore,


Please find the response below.



Query

Response

how to disable any keyboard command or specifically the delete key

We met your requirements at the sample level. You can disable any key or override the keyboard command in SFDiagramComponent by using the CommandManager. Using CommandMananger, you can change the built-in commands. CommandManager has a Commands property, Execute and  CanExecute callback method. Commands representing the storage of multiple command names denote the corresponding command object. Execute is used to run the command on the currently selected command target. CanExecute determines whether this command in its current state can be executed. You must specify which commands you want to change or disable in Commands property of CommandManager. If you want to disable the key, set false in the CanExecute method. To override the commands, you must set true in that method. You can also override the functionality of any commands by adding functionality to the Execute method. We have provided a link to our online UG for your convenience. We have also provided a sample for your reference.

 


UG link: https://blazor.syncfusion.com/documentation/diagram/commands#modify-the-existing-command

 

I wanted to communicate that the solution to my problem lies in the constraints that can be set in the various nodes, connectors and so on

We suspect that you want to restrict the deleting of all nodes and connectors while performing a delete operation with a keyboard delete key or a user handle or any button click. You can achieve your goal by removing the Delete constraint from all the nodes and connectors in the SfDiagramComponent's NodeCreating and ConnectorCreating events. The NodeCreating event is used to set the node's default properties and the ConnectorCreating event helps to assign the connector's default properties. Using the NodeCreating and ConnectorCreating events, you can remove delete constraints from nodes and connectors. We've included a code snippet for your convenience.

CodeSnippet:

 

<SfDiagramComponent NodeCreating="@OnNodeCreating" Connectors="@connectors" ConnectorCreating="@OnConnectorCreating" @ref="@diagram" Height="600px" Nodes="@nodes">

 

</SfDiagramComponent>

 

//Node Creating Event

  private void OnNodeCreating(IDiagramObject obj)

    {

        Node node = (obj as Node);

        node.Constraints &= ~NodeConstraints.Delete;

    }

 

//Connector creating event

    private void OnConnectorCreating(IDiagramObject obj)

    {

        Connector connector = (obj as Connector);

        connector.Constraints &= ~ConnectorConstraints.Delete;

    }

 



If we misunderstood your requirement, could you please explain it in full detail? It will be helpful to provide a better solution.


Note: In the first query, we provided a solution to disable the delete key by overriding our default functionality. It is not dependent on the second query.


Regards,

Sumathi U.


Attachment: Forum179563_7cc269ba.zip

Loader.
Live Chat Icon For mobile
Up arrow icon