Why do I have trouble accessing my custom symbol from the Diagram.NodeDoubleClick event handler?
Why do I have trouble accessing my custom symbol from the Diagram.NodeDoubleClick event handler?
The symbol object is a composite node that is made up of several other child nodes. Clicking on a symbol generates the Diagram.NodeDoubleClick event for each of these child nodes, and so attempting to directly cast the NodeMouseEventArgs.Node member to the symbol type will result in an invalid cast exception. This condition can be avoided by providing a simple type check for the required symbol class. The following code shows an implementation:
[C#]
private void diagram1_NodeDoubleClick(object sender, Syncfusion.Windows.Forms.Diagram.NodeMouseEventArgs evtArgs) {
if ((evtArgs.Node != null) && (evtArgs.Node is MySymbol)) {
MySymbol symbolClicked = evtArgs.Node as MySymbol;
Trace.WriteLine("NodeDoubleClick");
}
}
[VB.NET]
Private Sub diagram1_NodeDoubleClick(ByVal sender As Object, ByVal evtArgs As Syncfusion.Windows.Forms.Diagram.NodeMouseEventArgs) Handles diagram1.NodeDoubleClick
If Not (evtArgs.Node Is Nothing) AndAlso (TypeOf evtArgs.Node Is MySymbol) Then
Dim symbolClicked As MySymbol = CType(evtArgs.Node, MySymbol)
Trace.WriteLine(symbolClicked.Name)
End If
End Sub
Conclusion
I hope you enjoyed learning about why you have trouble accessing your custom symbol from the Diagram.NodeDoubleClick event handler.
You can refer to the 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!