Articles in this section
Category / Section

I have a handler for a diagram node click event. How do I determine the identity of the node from the event argument?

2 mins read

I have a handler for a diagram node click event. How do I determine the identity of the node from the event argument?

The node(s) referenced by a diagram node related event such as Diagram.NodeClick, Diagram.NodeMoved etc., will be an instance of the actual object, and you can use the node's type information to ascertain it's identity. If the node has been assigned a uniquely identifiable name at some point during creation, then the Node.Name property can be used as well to access a particular node instance. The following code should give an idea,

C#

// Handler for the Diagram.NodeClick event. Determine the node that was clicked on
private void diagramComponent_NodeClick(object sender, Syncfusion.Windows.Forms.Diagram.NodeMouseEventArgs evtArgs)
{
// Check whether the node clicked is a custom symbol
if(evtArgs.Node is MySymbol)
{
Trace.WriteLine("Node is a custom symbol type");
MySymbol mysmbl = evtArgs.Node as MySymbol;
MessageBox.Show(String.Concat("The custom symbol name is '", mysmbl.Name, "'"));
}
else if(evtArgs.Node is Symbol)
{
Trace.WriteLine("Node is a generic symbol");
Symbol symbl = evtArgs.Node as Symbol;
MessageBox.Show(String.Concat("The symbol name is '", symbl.Name, "'"));
}
else // Node is a non-Symbol node
{
// Ignore if the event is being generated for a Symbol's child node
if((evtArgs.Node.Parent != null) && !(evtArgs.Node.Parent is Symbol))
{
Trace.WriteLine(evtArgs.Node.GetType());
MessageBox.Show(String.Concat("The node name is '", evtArgs.Node.Name, "'"));
}
}
}

 

VB

' Handler for the Diagram.NodeClick event. Determine the node that was clicked on
Private Sub diagramComponent_NodeClick(ByVal sender As Object, ByVal evtArgs As Syncfusion.Windows.Forms.Diagram.NodeMouseEventArgs)
' Check whether the node clicked is a custom symbol
If TypeOf evtArgs.Node Is MySymbol Then
Trace.WriteLine("Node is a custom symbol type")
Dim mysmbl As MySymbol = evtArgs.Node as MySymbol
MessageBox.Show(String.Concat("The custom symbol name is '", mysmbl.Name, "'"))
Else If TypeOf evtArgs.Node Is Symbol Then
Trace.WriteLine("Node is a generic symbol")
Dim symbl As Symbol = evtArgs.Node as Symbol
MessageBox.Show(String.Concat("The symbol name is '", symbl.Name, "'"))
Else ' Node is a non-Symbol node
' Ignore if the event is being generated for a Symbol's child node
If Not (evtArgs.Node.Parent Is Symbol) Then
Trace.WriteLine(evtArgs.Node.GetType())
MessageBox.Show(String.Concat("The node name is '", evtArgs.Node.Name, "'"))
End If
End If
End Sub

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied