Readonly Diagram -> Allow Only Selection and Double Click

Hi,

I need to make the diagram control as read only. I can achieve by setting DiagramConstraints = None.
However, diagram elements such as nodes and connectors should be able to select and double click event should work.
How can I achieve that?

Could you please help me about that?

Kind Regards
Sinan Oran

7 Replies 1 reply marked as answer

AR Aravind Ravi Syncfusion Team August 5, 2020 05:04 AM UTC

Hi Sinan,

We have created a sample to disable interactions in diagram and enable selection for the diagram. To disable interaction or any editing in the diagram set diagram tool as None. If we want to select a node or connector in the diagram and disable interaction in the diagram means then set diagram Tool as None | SingleSelect. So if we perform any interaction in diagram means diagram do not get edited and on selecting the node or connector , the node gets selected. While double click on the diagram DoubleClick event gets fired.  Please refer the below code snippet for how to set diagram tool
 
 
DiagramProperties model = new DiagramProperties(); 
model.Tool = Tool.None | Tool.SingleSelect; 
 ViewData["DiagramModel"] = model; 
 
For more information about diagram tool selection, please refer to below UG documentation link 
 
 
Regards 
Aravind Ravi 



SO Sinan Oran August 5, 2020 07:45 AM UTC

Hi Aravind,

I'm not able to see DiagramProperties class. Can you please send an example?

Kind Regards
Sinan Oran


AR Aravind Ravi Syncfusion Team August 5, 2020 11:12 AM UTC

Hi Sinan, 
 
We have created a sample to disable interaction in the diagram and enable editing the nodes and connectors. Please find the sample in below link 
 
 
Regards 
Aravind Ravi 



SO Sinan Oran August 5, 2020 12:30 PM UTC

Hi Aravind,

I think I couldn't explain my problem.

I have one screen. Users are able to add , edit or view diagrams in this screen.

If the user doesn't have edit permission. I want to show diagram as readonly. Also,  we have some configuration on nodes and connectors.
When user double clicks to connectors or nodes, we show this configuration as popup.

If user doesn't have edit permission, I'm setting Diagram.Constraints = DiagramConstraints.None | DiagramConstraints.Zoom. 
So the user isn't able to do anything on diagram.
However, I want to the user to be able to select node or connectors on diagram and then double click (nothing else).

In the example which you shared, I'm able to everything on diagram.

Additionally, I changed Diagram.Constraints = DiagramConstraints.None | DiagramConstraints.Zoom | DiagramConstraints.UserInteraction. 
But the user is able to delete nodes and connectors on diagram in this case.

Kind Regards
Sinan Oran


AR Aravind Ravi Syncfusion Team August 6, 2020 08:16 AM UTC

Hi Sinhan, 

By using the NodeConstraints and ConnectorConstraints we can able to restrict the node and connector remove from diagram. Remove the Delete constraints from the node and connector constraints. So that when you try to delete the node or connector , it do not gets removed from the diagram. Instead of set the diagram constraints, set diagram tool as None | SingleSelect. Please find the below code snippet for how to set node constraints 

Connector connector = new Connector(); 
            connector.Name = "line" + model.Connectors.Count + 1; 
            connector.TargetNode = targetNode; 
            connector.SourceNode = sourceNode; 
            connector.SourcePort = sourcePort; 
            connector.TargetPort = targetPort; 
            connector.Constraints = ConnectorConstraints.Default & ~ConnectorConstraints.Delete; 

FlowShape node = new FlowShape(); 
           node.Name = name; 
            node.Width = width; 
            node.Shape = shape; 
            node.Height = height; 
            node.OffsetX = offsetx; 
            node.Constraints = NodeConstraints.Default & ~NodeConstraints.Delete; 

DiagramProperties model = new DiagramProperties(); 
model.Tool = Tool.None | Tool.SingleSelect; 

We have attached a sample for your reference. Please find the sample in below link 


Regards 
Aravind Ravi 


Marked as answer

SO Sinan Oran August 6, 2020 01:57 PM UTC

Thank you Aravind for your help.


AR Aravind Ravi Syncfusion Team August 7, 2020 03:52 AM UTC

Hi Sinhan, 
 
Most Welcome. 
 
Regards 
Aravind Ravi 


Loader.
Up arrow icon