Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to control and get data from TreeView Control

Status
Not open for further replies.

castor2003

Programmer
Jul 5, 2003
115
LC
I have succeeded in having my first TreeView working and boy I am excited. However, there seem to be little help around for it I can't find the help file. Do you know where I can find it? It is 'Cmctl198.chm'. I can't seem to find it on my PC.

I would like to do two things with my treeview.

1. to save the path each time a user makes a selection

Code:
 + MAIN
 |--+LEVEL1
 |   |__LEVEL2
 |
 |--+LEVEL1
    |__LEVEL2
	|__LEVEL3

If Item 'LEVEL3' is selected, I want to store [ MAIN\LEVEL1\LEVEL2\LEVEL3] in textbox or label on screen that changes as the user makes the selection.


SECONDLY

I Want to be able to use [ MAIN\LEVEL1\LEVEL2\LEVEL3] to show 'LEVEL3' as being selected programmatically.


I can't seem to be able to
 
Castor,

To get to the Help file, I usually go into Treeview properties (right-click on the treeview in design mode and select the bottom menu item), then click Help. Alternatively, select TreeView Help from that same menu.

To answer your first question, I think you need the node's FullPath property.

Mike


Mike Lewis
Edinburgh, Scotland
 
Mike

I did not get the Help file. Anyway, thanks for the fullpath answer. I am working at my final two hurdles in this TreeView task.

1. Using a node key, I want to programmatically select it. 2 Then prohibit collapsing and expanding - Disable
 
Hi castor,

I can't find the help file for download anywhere either!
Meantime, I've been mucking with the TreeView control a fair bit in VBA. To answer your questions:

1a. To reference any node by its key, use myTreeViewCtrl.Nodes("myKey")
1b. To select that node, use myTreeViewCtrl.Nodes("myKey").Selected = True

Of course, if there's any repetition then for performance, you'll want to enclose it in a "With myTreeViewCtrl ... End With" block, and then you might want to Dim myNode as Node and Set myNode = myTreeViewCtrl.Nodes("myKey") if you're planning on using it for more than one function.

2a. First of all, go into the TreeView-specific properties and set its display type to 4 - this shows just the lines and not the plus/minus, that way people won't expect to be able to expand/collapse. It won't stop it happening though, if they double-click.
2b. My trouble with coding collapsing/expanding in VBA is a lack of events, but if you're working in VB you may have more - or maybe there's a way to add more. Anyway, each node has a .Expanded property, so I run a bit of code in the Form_Timer procedure to handle all my expansion code if it deviates from default behaviour. For example, if I want to collapse all other branches apart from the selected one, I set myNode.Parent.Expanded = False and then do myNode.EnsureVisible which expands the tree just enough to view my node of choice. You'll have to improvise (or understand VBA events better than me!)

Let me know how you get on.

Al
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top