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

Loop through all treeview nodes

Status
Not open for further replies.

eelisdotnet

Programmer
Oct 3, 2004
10
FI
Hi

I have a treeview with checkbox=true and I'm trying to loop through all nodes, and get only the checked ones (treenode.checked = true) to an ArrayList.

The code goes like:
[tt]
Friend Sub SetCheckedList(Optional ByVal bolUpdate As Boolean = True, Optional ByRef tn As Object = Nothing)
If tn Is Nothing Then tn = Me.TopNode
Dim enumerator As IEnumerator = tn.Nodes.GetEnumerator
Dim node As TreeNode

If bolUpdate Then Me.BeginUpdate()

If Not tn Is Nothing Then

While enumerator.MoveNext
node = enumerator.Current
If node.Checked = True Then

Dim str As String = node.FullPath
checkedList.Add(str)


ElseIf node.GetNodeCount(False) > 0 Then

SetCheckedList(False, node)

End If

End While
End If

If bolUpdate Then Me.EndUpdate()
End Sub
[/tt]

The ElseIf is because I don't want to get child nodes if the parent node is already checked.
The problem starts when the ArrayList (named checkedList) shows only some of the checked, and when treenode is collapsed, it sometimes get all the checked nodes.
I would like to loop through all the treeview nodes, regardless of collapsed/expanded nodes.

Thanks for any ideas....

eelis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top