Click to See Complete Forum and Search --> : Can Anyone teach me how to......


Derek
February 18th, 2000, 10:46 AM
Hi,
Can anyone out there teach me how to create the treeview control in Visual Basic.
I tried the tutorials and they didn't workout too well. Do reply .
Thanks alot in advance,
Derek

Kyle Burns
February 18th, 2000, 11:15 AM
The TreeView control is a little bit too involved to just "tell someone how to use it". Please let me know what specific questions you have and I will be more than happy to give you whatever help I can to get you pointed in the right direction. I've found the Controls Reference to be an extremely valuable tool.

Derek
February 18th, 2000, 10:40 PM
Hi Kyle,
How you doing? I checked out the treeview control in the msdn Cd but didn't really understand how to start out with it. I would appreciate it if you could tell what to start off with first. When you did the treeview control what did you start of with first?
Looking forward to hearing from you,
Derek

Kyle Burns
February 21st, 2000, 08:54 AM
It's not much of a start, but it may give you a push in the right direction. Add the Windows Common Controls to your toolbox, place a treewview on a form, and put the following code in:

private Sub Form_Load()
Dim oNode as Node
set oNode = TreeView1.Nodes.Add(, , "Top", "Top Level Node")
set oNode = TreeView1.Nodes.Add("Top", tvwChild, "Child", "Child Node")
set oNode = nothing
End Sub



Hope this helps at least a little.

Derek
February 21st, 2000, 10:35 PM
Hi Kyle,
Thanks alot for your help. I will give this a try and will let you know how i did. Also do let me know if there is anything more to this. Can you give me the names of some sites where i can find Vb Tutorials and code . Thanks alot in advance,
Derek

Derek
February 22nd, 2000, 12:12 AM
Hi Kyle,
Ok I made the Treview the way you told me to and it came out great. Now what i want to know is how do i give it a function to do something.for Example suppose i have a child node called "EXIT" and i want to give the command END. Now you know what happens with that Command. How would i do this?
Thanks and this is really exciting,
Derek

Chris Eastwood
February 22nd, 2000, 03:16 AM
I would recommend that you never, ever, use the 'END' statement in Visual Basic - you're opening yourself up to all kinds of bugs and problems later on down the line (and serious ones too - possible GPF's, files renaming locked, lost data etc).

The correct way to exit from a program in VB is to unload all the forms and objects that a program is using.

eg.

Say that you have a button called 'cmdExit' on your form with a caption of "Exit" :


private Sub cmdExit_Click()
Unload me
End Sub




This code would unload the form - and if it's the only form in the project, end your program also.

Now, getting back to your original problem - say you have a Node called 'Exit' (and I assume you mean the caption of the node), then the following code will do the job for you :


private Sub TreeView1_NodeClick(byval Node as MSComctlLib.Node)
'
If Node.Text = "Exit" then
Unload me
End If
'
End Sub




You'll find that most programmers will never check the 'text' of a node - the way to identify a node is through either it's Tag or Key property.

eg.

When you come to build up the TreeView nodes :


private Sub Form_Load()
Dim nNode as Node
'
set nNode = TreeView1.Nodes.Add(, , "root", "ROOT")
nNode.Tag = "ROOT"
'
set nNode = TreeView1.Nodes.Add("root", tvwChild, "exit", "Exit")
nNode.Tag = "EXIT"
'
End Sub




Now you'd simply check on the 'Tag' or 'Key' property in the NodeClick event to see which node was clicked.


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb