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

Refresh Treeview Child Nodes 1

Status
Not open for further replies.

bobbarker

Programmer
Dec 20, 2001
83
0
0
GB
I have a tree view. Child items are populated from a recordset queried from a property of the parent item in the tree.

When the contents of the recordset change (records added, deleted etc) I would like to refresh just the child items of the affected parent, not have to refresh the whole tree.

To do this I guess I need to first remove the child items and then re-add them plus any additions from the recordset change.

I am not sure how to navigate around just the child items in that parent and remove them.

Any advise would be appreciated.

Thanks
 
Remove Children...
Code:
Private Sub Command1_Click()
  RemoveChildren TreeView1.SelectedItem
End Sub

Private Sub RemoveChildren(Node As MSComctlLib.Node)
  If Not Node Is Nothing Then
    While Node.Children
      TreeView1.Nodes.Remove Node.Child.Index
    Wend
  End If
End Sub

Setup Test Data...
Code:
Private Sub Form_Load()
  With TreeView1.Nodes
    .Add(, , "Parent1", "Test").Expanded = True
      .Add("Parent1", tvwChild, , "Test").Expanded = True
      .Add("Parent1", tvwChild, , "Test").Expanded = True
      .Add("Parent1", tvwChild, , "Test").Expanded = True
      .Add("Parent1", tvwChild, , "Test").Expanded = True
      .Add("Parent1", tvwChild, , "Test").Expanded = True
      .Add("Parent1", tvwChild, , "Test").Expanded = True
    .Add(, , "Parent2", "Test").Expanded = True
      .Add("Parent2", tvwChild, , "Test").Expanded = True
      .Add("Parent2", tvwChild, , "Test").Expanded = True
      .Add("Parent2", tvwChild, , "Test").Expanded = True
    .Add(, , "Parent3", "Test").Expanded = True
      .Add("Parent3", tvwChild, , "Test").Expanded = True
      .Add("Parent3", tvwChild, , "Test").Expanded = True
      .Add("Parent3", tvwChild, , "Test").Expanded = True
    .Add(, , "Parent4", "Test").Expanded = True
      .Add("Parent4", tvwChild, , "Test").Expanded = True
      .Add("Parent4", tvwChild, , "Test").Expanded = True
      .Add("Parent4", tvwChild, , "Test").Expanded = True
  End With
End Sub

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top