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

Treeview Refresh

Status
Not open for further replies.

simon1974

Technical User
Apr 2, 2002
43
US
I have a form with multiple treeview controls. The nodes are fed via code from hierarchical tables native to the Access database. I have several "new record" forms that launch off of the main form which essentially create new records in the native tables. I would like to have a way, when the "new record" forms close and return to the main form, to have the treeview controls refresh to represent the new tree(s). However, I don't want them to recollapse - I want them to stay in the same state (some nodes expanded, some collapsed, however the user currently is navigating). I have tried Form.Refresh and it updates all nodes, but it collapses everything. Any help would be appreciated.
 
This code will re-expand nodes in a single treeview control. I am not sure if this is the most efficient way to do this but it seems to work well.

Code:
Dim nodName(Me.MailTree.Nodes.Count) As Double
Dim nod
'Populate an array with expanded nodes.
    For Each nod In Me.YourTreeViewName.Nodes
        If nod.Expanded = True Then
            x = x + 1
            nodName(x) = nod.Index
        End If
    Next
'requery your form here
    For y = 1 To x 'Rexpand the nodes
        YourTreeViewName.Nodes(nodName(y)).Expanded = True
    Next

HTH,
Eric
 
Let me fix an error:

Code:
Dim nodName() As Double
Dim nod
ReDim nodName(Me.YourTreeViewName.Nodes.Count)

'Populate an array with expanded nodes.
    For Each nod In Me.YourTreeViewName.Nodes
        If nod.Expanded = True Then
            x = x + 1
            nodName(x) = nod.Index
        End If
    Next
'requery your form here
    For y = 1 To x 'Rexpand the nodes
        YourTreeViewName.Nodes(nodName(y)).Expanded = True
    Next

Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top