Articles in this section

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

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 its 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, "'"))
    ElseIf 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

 

Conclusion

I hope you enjoyed learning about having a handler for a diagram node click event and determining the identity of the node from the event argument.

You can refer to WinForms Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Diagram example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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