Basic TreeView Question

Shep

Shep
Local time
Today, 05:39
Joined
Dec 5, 2000
Messages
364
I'm using Access 97

I've been experimenting with the TreeView control, and noticed that several here make use of it. In studying the code that the wizard generated, I see that the control is populated by tables or queries which must have related fields. I also note that some of the screenshots I've seen here have TreeViews which are action menus, not just heirarchal listings of records.

How do you populate those, do you create tables with the menu items as fields/records?

Thanks
 
look in the sample db section - I posted a static treeview example and others (Carnafex,CJBIRKIN) have posted dynamic Tree Control samples...

HTH,
Kev
 
There's also a walkthrough of how it's done on MS's Knowledge Base - don't have the link though.
 
Thanks Kevin,
I did look at that sample at my office, but it loads with an error; no object in this control. I took a second look just at the code, and I see that it's quite simple to add nodes. Cheers!
 
Thanks Kev, another basic question, if you please: What is the name of the Event for clicking on a node? I tried, for example: tvwTest_NodeClick() but it stated that this was not a named event. I'm using the 5.0 TreeView control.

[Edit] I'm looking for other samples as I write this..
 
what version of Access are you running Shep? I'm using A XP...

the even NodeClick() is one that I create myself as there are no predefined events for this control (or most ActiveX controls for that matter)...

Kev
 
I'm using Access 97

Right, I created a NodeClick() event as well. I saw it being used in a sample. It's not on the event list for the control, as you state. But I get an error saying that it's not a named event. A couple other events I also found being used in a sample work well, for example the OnClick() event.
 
Shep -

Instead of NodeClick() try just using Click() as in YOURTREENAME_Click(). This should work for you... Let me know...

Kevin
 
Thanks Kev,
Click() is an event for the control itself.

I found the problem, maybe this will help others. Then again, maybe everyone else already knew it.

The example in the help file is incorrect:

Private Sub TreeView1_NodeClick(ByVal Node As Node)

should be..

Private Sub TreeView1_NodeClick(ByVal Node As Object)

It's discussed in the Microsoft Knowledge Base Article - 172167

Cheers
 
If your also curious, you can use the ordinary click event as well, as long as you do this little bit of code:


Code:
private sub mytree_click()

    dim oTree as treeview, mNode as node
    set otree = me!mytree.object
    set mNode = otree.selectedItem()

    'now mNode is the node I can use
    ...

end sub
This way is the same as the NodeClick(...) event, just with a few extra lines of code. I used this heaps before I found the way you did it Shep. I should be posting a new treeview example later as well, (in a few weeks), because I found out how to add drag'n'drop functionality to the tree. Sorta nice that you can add,edit,delete, move and copy records in the related table using the treeview itself. It looks really nice to my employers :D .

Ta

Jason
 
Last edited:
Very good Jason, I've added that snippet to my little treeview collection.
I'm becoming more comfortable with the treeview now; I can also add an example soon which shows how to add a Parent derived from a table, mixed with plain text entries. I'll be watching for yours.

Thanks
 

Users who are viewing this thread

Back
Top Bottom