By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,454 Members | 1,795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,454 IT Pros & Developers. It's quick & easy.

Multiple Informations in one Treeview Node

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Yavuz Bogazci" <ya***@bogazci.com> schrieb
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).
--
Armin

Nov 19 '05 #2

P: n/a
Hello,

"Yavuz Bogazci" <ya***@bogazci.com> schrieb:
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
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #3

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

thanks
yavuz bogazci

-----Original Message-----
Hello,

"Yavuz Bogazci" <ya***@bogazci.com> schrieb:
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 youcan use this class instead of the standard TreeNode. Notice that this classwill not work with the designer. If you want to retrieve a node from theTreeView, 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
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet
.

Nov 19 '05 #4

P: n/a
Hello,

"Yavuz Bogazci" <ya***@bogazci.com> schrieb:
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
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.