|
-
Feb 12th, 2007, 10:55 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Doubt about treeview and nodes
I have a doubt about using treeviews and nodes... I've been using the treeview with Java and C#, and when I worked with them I could easily "attach" some class to each node, and hence defining some custom properties for it (username, pass, address, connected, etc), and then while browsing the tree I was able to retrieve the type of the node, and using some specific functions of it.
How could I easily do this? does anyone have any tip or suggestion for something like this?
-
Feb 12th, 2007, 11:17 AM
#2
Lively Member
Re: Doubt about treeview and nodes
Use the node.tag to store your referenced object.
For example the following code has a form with a command button, a treeview and a class.
'Form Code
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim MyClass As New Class1
MyClass.User = "Test"
Dim Node As Node
Set Node = TreeView1.Nodes.Add(, , , MyClass.User)
Set Node.Tag = MyClass
End Sub
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Dim MyClass As Class1
Set MyClass = Node.Tag
Call MsgBox(MyClass.User)
End Sub
'Class1 code
Option Explicit
Private m_User As String
Public Property Get User() As String
User = m_User
End Property
Public Property Let User(Name As String)
m_User = Name
End Property
-
Feb 12th, 2007, 11:46 AM
#3
Thread Starter
Addicted Member
Re: Doubt about treeview and nodes
Thanks, I never used the VB6 Treeview control until now. Also, I thought the tag property only worked with strings.
-
Feb 12th, 2007, 11:49 AM
#4
Lively Member
Re: [RESOLVED] Doubt about treeview and nodes
Oh forgot to mention. If you declare a variable as an object, you can then use TypeOf to compare it to a specific type, for example:
VB Code:
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
dim MyObj as object
Dim MyClass As Class1
Set MyObj = Node.Tag
If typeof Myobj is class1 then
set MyClass=MyObj
Call MsgBox(MyClass.User)
end if
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|