Treeview windowstate save and restore

C

Co

Hi All,

I have this Treeview of which I want to save the window status when
I'm doing some action with the nodes.
After the action I want to restore the windowstate.
I save the windowstate in a Dictionary. The code I have does work
except that it doesn't expand the nodes
under the root node. All nodes under there are collapsed or expanded
the way I saved them.

What do I need to also save the expand or collapse for the nodes under
the root node?

Private tt As New Dictionary(Of String, Boolean)

Public Sub SaveTreeView(ByVal treeview As TreeView)

For Each node As TreeNode In treeview.Nodes
SaveTreeState(node)
Next

End Sub
Public Sub RestoreTreeView(ByVal treeview As TreeView)

For Each node As TreeNode In treeview.Nodes
RestoreTreeViewExpandedState(node)
Next

End Sub
Private Sub RestoreTreeViewExpandedState(ByVal objTreeNode _
As TreeNode)

Dim objChildTreeNode As Node

For Each objChildTreeNode In objTreeNode.Nodes
Dim ID As String = objChildTreeNode.row("ID").ToString
RestoreTreeViewExpandedState(objChildTreeNode)
If tt.ContainsKey(ID) Then
If tt(ID) Then
objChildTreeNode.Expand()
Else
objChildTreeNode.Collapse()
End If
End If

Next

End Sub

Private Function SaveTreeState(ByVal objTreeNode _
As TreeNode) As Dictionary(Of String, Boolean)

Dim objChildTreeNode As Node

For Each objChildTreeNode In objTreeNode.Nodes
Dim ID As String = objChildTreeNode.row("ID").ToString
SaveTreeState(objChildTreeNode)
tt.Add(ID, objChildTreeNode.IsExpanded)
Next

Return tt
End Function

Regards
Marco
The Netherlands
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top