eelisdotnet
Programmer
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
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