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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview 1

Status
Not open for further replies.

shaunhubbs

Technical User
Jun 6, 2005
57
CA
Hi all,

I am trying to create a simple form in Access to display a tree full of Sets with Items in them. The problem I am running into is, I believe, the syntax/parameters used by the TreeView ActiveX control.

Here is some simple code that I have written in the Form_Load even; any ideas why something this simple isn't working?

axTreeView.Nodes.Add , , "Set", "Set 1234"
axTreeView.Nodes.Add "Set", tvwChild, "Item", "Screw"

Does the second line, first paramater not refer to where the child should be placed under? I have seen lots of code examples for treeview, but cannot seem to find a good explanation on how to associate children under their parents and what the parameters are. Do you think I have something set up wrong within Access maybe?

Any help is greatly appreciated. Thanks.

- Shaun
 
So I sort of figured out my own problem: the children I was inserting were there, but I had to insert a button to expand the nodes and the top level (parents/roots) did not have a '+' beside them.

Anyone know how to get the '+' beside the top level entries in the treeview?

(Starting to feel like I'm talking to myself.) ;o)

- Shaun
 
Right click the Tree View control, then click properties. Some happy combination the should do the trick. Especially, the style and line style properties.

Ex.
Style = 7 - tvwTreelinesPlusMinusPictureText
LineStyle = 1 - tvwRootLines


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
You can also have the nodes automatically expand like so...

Dim oNode as Node

Set oNode = axTreeView.Nodes.Add(, , "Set", "Set 1234")
oNode.Expanded = True

Set oNode = axTreeView.Nodes.Add( "Set", tvwChild, "Item", "Screw")
oNode.Expanded = True


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks so much for those responses George. One more quick question though:

Can I have one of the nodes selected and then have a button to just fully expand what is within that node? What would that code look like?

Thanks again.

- Shaun
 
I'm not the greatest at TreeView's, but I'll give it a shot.

In the click event, add teh following code.

Code:
Dim oNode as Node
Dim oSelectedNode as node

Set oSelectedNode = axTreeView.SelectedItem

For Each oNode In oSelectedNode.Child
    oNode.Expanded = True
Next

This may only expand the nodes to the next level. Unless there's something I'm missing, to expand nodes all the way down, you would need to add recursion. Like I said, I'm no expert with the treeview control, but I hope this helps.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
It doesn't seem to work for me... When it hits the .Child it says that that's not supported. I tried this instead:

For Each Node In SelectedItem.Nodes
Node.Expanded = True

And of course that would've been too easy. I did manage to get all to expand with:

For Each Node In axTreeView.Nodes
Node.Expanded = True
Next

But that is pretty useless as I have thousands of items in the list.

Any other ideas from anyone on how to adapt the above for just a selected item?

Thanks again.

- Shaun
 
I searched tektips and found this... thread222-575238

Then I thought, Hmmmm... maybe this will work.

Dim oNode As Node

axTreeView.SelectedItem.Expanded = True

For Each oNode In axTreeView.Nodes
If Not oNode.Parent Is Nothing Then
If oNode.Parent.Key = axTreeView.SelectedItem.Key Then
oNode.Expanded = True
End If
End If
Next

It's not perfect, but hopefully it will be a good starting point.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
That seems to work quite well actually George. Thanks again for your help. I had to do nothing to that code to make it work for me.

Thanks.

- Shaun
 
The problem I had was that after expanded the nodes, so 'newly' visible nodes had a + next to it, indicating that there we more nodes. When I clicked the plu to close the node, it re-opened the node. This probably happened because I had this code in the click event.

Anyway, if you're satisfied with it, good. That's the important thing.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Yep, I am satisfied with what it does for now. I am sure some minor modifications could be done to make it even more effective. Thanks George.

- Shaun
 
Glad to help.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top