How to create NodeID property for the TreeNodeAdv in WinForms TreeViewAdv?
Create custom property
In the WinForms TreeView, you can add custom properties by creating custom TreeNodeAdv class that is inherited from the TreeNodAdv. The following code example demonstrates the same.
C#
//Creates custom TreeNode class. public class CustomTreeNodeAdv : TreeNodeAdv { public CustomTreeNodeAdv() { // Initializes according to the need. } private int m_NodeId; /// <summary> /// Gets/Sets the ID in the TreeNodeAdv. /// </summary> public int ID { get { return m_NodeId; } set { m_NodeId = value; } } } for (int i = 0; i < 100; i++) { CustomTreeNodeAdv node = new CustomTreeNodeAdv(); node.ID = i; node.Text = "Node" + i.ToString(); this.treeViewAdv1.Nodes.Add(node); } //Displays the Node ID. MessageBox.Show("ID: " + (this.treeViewAdv1.SelectedNode as CustomTreeNodeAdv).ID.ToString());
VB
'Creates custom TreeNode class. Public Class CustomTreeNodeAdv Inherits TreeNodeAdv Public Sub New() 'Initializes according to the need. End Sub Private m_NodeId As Integer ''' <summary> ''' Gets/Sets the ID in the TreeNodeAdv. ''' </summary> Public Property ID() As Integer Get Return m_NodeId End Get Set(ByVal value As Integer) m_NodeId = value End Set End Property End Class For i As Integer = 0 To 99 Dim node As New CustomTreeNodeAdv() node.ID = i node.Text = "Node" & i.ToString() Me.treeViewAdv1.Nodes.Add(node) Next i ' Displays the Node ID. MessageBox.Show("ID: " & (TryCast(Me.treeViewAdv1.SelectedNode, CustomTreeNodeAdv)).ID.ToString())
Samples:
C#: https://www.syncfusion.com/downloads/support/directtrac/136015/TreeViewAdvNodeId-690740322.zip
VB: https://www.syncfusion.com/downloads/support/directtrac/138428/TreeViewAdvNodeId_VB251737780.zip
I hope you enjoyed learning about how to create NodeID property for the TreeNodeAdv in WinForms TreeViewAdv.
You can refer to our WinForms TreeView’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms TreeView documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms 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 WinForms TreeView and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!