LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Returning checked Nodes from Treeview form control

Tree walking routines... I hate them too.

Drop a TreeView control and a CommandButton control onto a UserForm then use
this example code.


Private Sub UserForm_Initialize()
Dim nod As Node

TreeView1.CheckBoxes = True

With TreeView1.Nodes
Set nod = .Add(Relationship:=tvwChild, Text:="A1")
Set nod = .Add(Relative:=nod, Relationship:=tvwChild, Text:="A2")
Set nod = .Add(Relative:=nod, Relationship:=tvwChild, Text:="A3")
Set nod = .Add(Relationship:=tvwChild, Text:="B1")
Set nod = .Add(Relative:=nod, Relationship:=tvwChild, Text:="B2")
Set nod = .Add(Relative:=nod, Relationship:=tvwChild, Text:="B3")
Set nod = .Add(Relationship:=tvwChild, Text:="C1")
Set nod = .Add(Relative:=nod, Relationship:=tvwChild, Text:="C2")
Set nod = .Add(Relative:=nod, Relationship:=tvwChild, Text:="C3")
End With
End Sub

Private Sub CommandButton1_Click()
Dim nod As Node, str As String

If TreeView1.Nodes.Count 0 Then
Set nod = TreeView1.Nodes(1)

Do
If nod.Checked Then str = str & IIf(str = "", "", ", ") &
nod.Text
If Not nod.Child Is Nothing Then
Set nod = nod.Child
ElseIf Not nod.Next Is Nothing Then
Set nod = nod.Next
Else
Do
Set nod = nod.Parent
If Not nod Is Nothing Then
If Not nod.Next Is Nothing Then
Set nod = nod.Next
Exit Do
End If
Else
Exit Do
End If
Loop
If nod Is Nothing Then Exit Do
End If
Loop

MsgBox str

End If
End Sub



--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Dan Thompson" wrote in message
...
I am using the Treview form control on a userform.
I have a Root node called "Root" and a Child Node Called "Charts" than I
have child or grandchild nodes off of the "Charts" Node, 5 of them to be
exact which are named "c1", "c2", "c3", "c4" and "c5". all of the nodes in
my
tree have empty check boxes beside the node name. What I would like to be
able to do is to go through and check for example nodes "c2" and "c4"
ect..
and then programaticly have vba return in a message box whcih nodes were
checked.

Any Ideas on how to do this ?

Dan.



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding nodes to treeview John Excel Programming 3 December 1st 04 09:07 PM
Treeview control in an Excel form Theo Excel Programming 3 May 24th 04 07:47 AM
Returning control to form P. Dileepan[_2_] Excel Programming 11 April 11th 04 02:25 AM
treeview add nodes Serkan[_2_] Excel Programming 3 October 3rd 03 09:55 AM
TreeView: add more than one node to nodes collection Peter[_25_] Excel Programming 3 September 5th 03 12:15 PM


All times are GMT +1. The time now is 03:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"