TreeView
-
- NewLounger
- Posts: 9
- Joined: 17 May 2013, 21:53
TreeView
I'm currently in the process of writing a "fuel" program in VBA for my company using Excel & Access 2003 (XP Pro).
I came accross a "TreeView" routine written by Hans Vogelaar. I would like to use this to display a listing of equipment by classification for selection purposes.
My question is; is there a way to either double-click on an "extended box" or highlight an "extended box" then click on a "selection command button" and capture the selection in the TreeView to pass back to the program for further processing?
P.S. I noticed that the "extended boxes" have "tags", not sure if I can utilize or not.
I came accross a "TreeView" routine written by Hans Vogelaar. I would like to use this to display a listing of equipment by classification for selection purposes.
My question is; is there a way to either double-click on an "extended box" or highlight an "extended box" then click on a "selection command button" and capture the selection in the TreeView to pass back to the program for further processing?
P.S. I noticed that the "extended boxes" have "tags", not sure if I can utilize or not.
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: TreeView
Welcome to Eileen's Lounge!
The currently selected node in a TreeView control is stored in its SelectedItem property.
The nodes themselves don't have a double-click event, but the treeview control as a whole has a double-click event. You can inspect the SelectedItem property in this event.
For example, for a treeview named TreeView1:
You could also look at the SelectedItem property in the click event of a command button.
The currently selected node in a TreeView control is stored in its SelectedItem property.
The nodes themselves don't have a double-click event, but the treeview control as a whole has a double-click event. You can inspect the SelectedItem property in this event.
For example, for a treeview named TreeView1:
Code: Select all
Private Sub TreeView1_DblClick()
With Me.TreeView1
If .SelectedItem Is Nothing Then
MsgBox "No node selected", vbInformation
Else
' Do something with the selected item, for example
MsgBox .SelectedItem.Text, vbInformation
End If
End With
End Sub
Best wishes,
Hans
Hans
-
- NewLounger
- Posts: 9
- Joined: 17 May 2013, 21:53
Re: TreeView
Keep getting message "Object does not support proprty or method"?
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: TreeView
Which version of the TreeView control did you insert?
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- NewLounger
- Posts: 9
- Joined: 17 May 2013, 21:53
Re: TreeView
I do not have "Microsoft TreeView Control" listed?
I am using Excel 2003 VBA to pull from Access tables to populate Tree
I should mention that I modified the code to utilize ADO vs. DAO (not sure if this is what's causing the problem)
I am using Excel 2003 VBA to pull from Access tables to populate Tree
I should mention that I modified the code to utilize ADO vs. DAO (not sure if this is what's causing the problem)
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: TreeView
How did you get the TreeView control then?
I don't think DAO or ADO should matter.
I don't think DAO or ADO should matter.
Best wishes,
Hans
Hans
-
- NewLounger
- Posts: 9
- Joined: 17 May 2013, 21:53
Re: TreeView
I believe this is one that you created for use on Excel VBA forms.
The code came with Class Modules clsNode and clsTreeView.
The code came with Class Modules clsNode and clsTreeView.
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: TreeView
Ah - are you referring to the treeview created by Jan Karel Pieterse with Peter Thornton, mentioned in All-VBA treeview?
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: TreeView
Thanks - I thought you were using the ActiveX treeview.
The treeview developed by Pieterse and Thornton has a Click event that passes the node clicked in its event procedure:
This is used in the demo userform to display information about the node in the caption of a label below the treeview:
No DoubleClick event has been defined, as far as I can tell.
The treeview has a property ActiveNode (of type clsNode) that represents the selected (active) node. For example you could create a command button cmdTest on the userform, with the following Click event procedure:
where mcTree is the name of the treeview (I used the name from the demo form here).
The treeview developed by Pieterse and Thornton has a Click event that passes the node clicked in its event procedure:
Code: Select all
Event Click(cNode As clsNode)
Code: Select all
'This gets fired when a node is clicked
Private Sub mcTree_Click(cNode As clsNode)
Dim s As String
With cNode
s = .Caption & IIf(mcTree.CheckBoxes, " Checked:" & .Checked, "") & vbCr & _
.Key & " Index:" & .Index & " VisIndex:" & .VisIndex & " Level:" & .Level
End With
Me.labInfo.Caption = s
End Sub
The treeview has a property ActiveNode (of type clsNode) that represents the selected (active) node. For example you could create a command button cmdTest on the userform, with the following Click event procedure:
Code: Select all
Private Sub cmdTest_Click()
' Do something with the active node, e.g. display its caption
MsgBox mcTree.ActiveNode.Caption, vbInformation
End Sub
Best wishes,
Hans
Hans
-
- NewLounger
- Posts: 9
- Joined: 17 May 2013, 21:53
Re: TreeView
I can't thank you enough, we are making progress.
ActiveNode works, just need to explore other properties of ActiveNode's.
Going to try Event Click next.
All of our fixed assets are assigned a fixed asset ID # (FAID).
My intent is to incorporate this into the Node somehow, then retrieve it when the Node is selected.
Any ideas.
Thanks
ActiveNode works, just need to explore other properties of ActiveNode's.
Going to try Event Click next.
All of our fixed assets are assigned a fixed asset ID # (FAID).
My intent is to incorporate this into the Node somehow, then retrieve it when the Node is selected.
Any ideas.
Thanks
-
- NewLounger
- Posts: 9
- Joined: 17 May 2013, 21:53
Re: TreeView
I think I have it.
I assigned the FAID to the Key property.
I can retrieve the Key base on Node selected.
Thanks again for all your help.
I assigned the FAID to the Key property.
I can retrieve the Key base on Node selected.
Thanks again for all your help.
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- NewLounger
- Posts: 9
- Joined: 17 May 2013, 21:53
Re: TreeView
Hans, I have one last question before I wrap this up.
Is there a way to collapse the tree prior to viewing?
The reason I ask is;
1) This will make the tree fit into the window (nice presentation)
2) My managers will not have to look through an expanded tree to find their equipment. If collapsed they can go directly to the appropriate node, expand, then select their equipment.
Thanks again
Is there a way to collapse the tree prior to viewing?
The reason I ask is;
1) This will make the tree fit into the window (nice presentation)
2) My managers will not have to look through an expanded tree to find their equipment. If collapsed they can go directly to the appropriate node, expand, then select their equipment.
Thanks again
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: TreeView
In the code where the tree is populated, there is a line
Below this, insert the lines
ExpandToLevel 0 will display the treeview completely collapsed, i.e. only the root node will be visible.
ExpandToLevel 1 will display the treeview collapsed to level 1, i.e. the root node and its immediate descendants will be visible.
Etc.
Code: Select all
.PopulateTree
Code: Select all
.ExpandToLevel 0
.Refresh
ExpandToLevel 1 will display the treeview collapsed to level 1, i.e. the root node and its immediate descendants will be visible.
Etc.
Best wishes,
Hans
Hans
-
- NewLounger
- Posts: 9
- Joined: 17 May 2013, 21:53
Re: TreeView
Level 2 is the ticket.
Since all the equipment is at Level 3, I also check to make sure that Node.Level = 3
If Node.Level=3, capture the Key (FAID) and complete the form for that FAID.
Works exactly the way I was hoping it would.
Back to wrting the rest of the code.
Thanks again Hans for all your help.
Since all the equipment is at Level 3, I also check to make sure that Node.Level = 3
If Node.Level=3, capture the Key (FAID) and complete the form for that FAID.
Works exactly the way I was hoping it would.
Back to wrting the rest of the code.
Thanks again Hans for all your help.
-
- Microsoft MVP
- Posts: 656
- Joined: 24 Jan 2010, 17:51
- Status: Microsoft MVP
- Location: Weert, The Netherlands
Re: TreeView
Thanks for helping Magoo implement my treeview Hans!
-
- Administrator
- Posts: 78671
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands