)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create NodeID property for the TreeNodeAdv in WinForms TreeViewAdv?

Platform: WinForms |
Control: TreeViewAdv |
Published Date: May 11, 2015 |
Last Revised Date: February 5, 2020

Create custom property

In the TreeNodeAdv, 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#: http://www.syncfusion.com/downloads/support/directtrac/136015/TreeViewAdvNodeId-690740322.zip

VB: http://www.syncfusion.com/downloads/support/directtrac/138428/TreeViewAdvNodeId_VB251737780.zip

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon