Multiple Informations in one Treeview Node

Y

Yavuz Bogazci

Hi,

i have created a treeview and this works nice. I have now
a problem: I want to store 2 more Information to each
Treeview Node like UserID and CompanyID. How can i do
that?

Thanks
Yavuz Bogazci
 
A

Armin Zingler

Yavuz Bogazci said:
i have created a treeview and this works nice. I have now
a problem: I want to store 2 more Information to each
Treeview Node like UserID and CompanyID. How can i do
that?

Derive your own Node classe from the System.Windows.Forms.TreeNode class and
add the properties you need. Instead of adding instances of the
System.Windows.Forms.TreeNode class, add instances of your own class. This
can not be done by the designer (at least not by default).
 
H

Herfried K. Wagner [MVP]

Hello,

Yavuz Bogazci said:
i have created a treeview and this works nice. I have now
a problem: I want to store 2 more Information to each
Treeview Node like UserID and CompanyID. How can i do
that?

Derive a class from TreeNode and extend it by adding properties. Then you
can use this class instead of the standard TreeNode. Notice that this class
will not work with the designer. If you want to retrieve a node from the
TreeView, you must cast it in order to access its properties:

Assuming ExtendedTreeNode is the type name of your node class:

\\\
DirectCast(Me.TreeView1.Nodes(1), ExtendedTreeNode).UserID = 22
///

HTH,
Herfried K. Wagner
 
Y

Yavuz Bogazci

do you have a snipped of code of how to derive a class
with two properties an set them?

thanks
yavuz bogazci
 
H

Herfried K. Wagner [MVP]

Hello,

Yavuz Bogazci said:
do you have a snipped of code of how to derive a class
with two properties an set them?

Untested:

\\\
Public Class ExtendedTreeNode
Inherits TreeNode

Private m_ID As Integer
Private m_Name As String

Public Property ID() As Integer
Get
Return m_ID
End Get
Set(ByVal Value As Integer)
m_ID = Value
End Set
End Property

Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal Value As String)
m_Name = Value
End Set
End Property
End Class
..
..
..
Dim t As New ExtendedTreeNode
t.ID = 22
t.Name = "Foo Bar"
Me.TreeView.Nodes.Add(t)
///

HTH,
Herfried K. Wagner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top