Tree View Control Question (1 Viewer)

gblack

Registered User.
Local time
Today, 07:41
Joined
Sep 18, 2002
Messages
632
So I figured out the treeview and now it works just great... I can traverse my hierarchy just fine... now how can I use this?

Is the treeview just a visual, or can I actually utilize the data I am clicking on within?

What I want to do is to be able to choose a specific hierarchical path and once I stop (i.e. highlight a specified point in the TreeView) have the path be posted in a textbox within the Form that the TreeView is on... Seems easy enough but I can't seem to figure out how to post anything in terms of output from the TreeView...

As an Example... if the TreeView was akin to a folder structure... If the user clicked/drilled down three levels, once for "C:", once for "All Documents" and once for "Gary's Documents" and then highlight "Gary's Documents" (within the TreeView)... I am looking for some code to post the string output to a textbox that might look something like:
"C:\All Documents\Gary's documents"

Does anyone know how utilize the TreeView to do something like this, or can someone point me in the right direction?

Everything I look up online talks about how to actually populate the treeview itself... I have already done this... Now I am trying to figure out how I can get some hierarchical output from this control...

Nothing I saw on the forum talked about this issue... but admittedly I couldn't read all the posts on TreeViews, as there were a lot.

Thanks for any help (in advance)!
 

Minty

AWF VIP
Local time
Today, 07:41
Joined
Jul 26, 2013
Messages
10,373
Assuming your Treevview was called tvwListing on your forms module something like;

Code:
Private Sub tvwListing_NodeClick(ByVal Node As Object)
   
    Dim sNodeKey As String

    On Error GoTo errorHandler

    sNodeKey = Node.Key
    .... more code goes here...
 

gblack

Registered User.
Local time
Today, 07:41
Joined
Sep 18, 2002
Messages
632
Thanks for your help Minty,

I am not sure how to use that snippet of code you posted, or where to put it...I am kind of new to using activeX controls.

I only show 5 events in the properties of the TreeView control itself...

I don't see a "NodeClick" event... or any type of "click" event for the treeview control... Basically the Treeview events are: On Updated, On Enter, On Exit, On Got Focus, and On Lost Focus...

So I am kind of at a loss as to where I would apply this type of code. I did try using it but it gave me errors...

At this point I'd be happy if I could just capture the currently selected node (in the control) and output that to a textbox. And each time new node is chosen, then output that... Do you happen to have a snippet of code that can do that?
 
Last edited:

gblack

Registered User.
Local time
Today, 07:41
Joined
Sep 18, 2002
Messages
632
OK I see where the properties of the control doesn't give you all the possible event choices. If you go into the VBA Scripting section then choose the TreeView control from the dropdown on the left, and then choose the dropdown on the right there's a whole slew of events you can choose, one of them being NodeClick... then your Node.Key (or in my case I used Node.Text) can be used.

Thanks for giving me a bit to run with... It's not quite solved, but I can figure out the rest!

Thanks again Minty!
 

Minty

AWF VIP
Local time
Today, 07:41
Joined
Jul 26, 2013
Messages
10,373
To be honest I inherited a database with a TreeView, and have always found it a little "Interesting" to work with.
One thing I haven't figured is how to select a node item in code so that you are automatically placed on it after say searching for an underlying serial number.
 

Users who are viewing this thread

Top Bottom