Treeview  method question

Prysson
Prysson used Ask the Experts™
on
I have a wizard that has two pages to it.

In the first page the user selects an option from a drop down combo box. The value selected fills a treeview in the second page with certain items related to the option chosen.

However when the use click back and changes the item selected in the combo box the treeview does not "refresh" but instead simply adds the new items in addition to the values already populating the treeview nodes.


What I need is a statement that "counts" the nodes of the treeview to determin if the value is greater than 0 and if it does to run some kind of clear function to remove the existing nodes.

I simply dont know what th proper methods and form of the code would look like.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
what code do you have already?

Jon

Author

Commented:
which code?

I have the code that builds the treeview but that is not relevant to this issue. I dont have any code regarding what I am looking for.

IN short it should function something along the lines of an If Then

If Me!Treeview.Nodes.Count > 0 Then
Me!Treeview.Clear

Else
Rest of code....
End If

Something along those lines but I dont know what the methods are going to be nor do I know the structure of the code because I cant find decent documentation on treeview objects.

Commented:
Why not clear the nodes before you populate it?
TreeViewCtl1.Nodes.Clear

(I'm going to call the first form with the combo box Form1 and the second form with the treeview Form2)

Does something like that work?  That's what I usually do.  Clear out what was previously in there before adding anything new.

Where do you populate the nodes?  On Form2's Form_Load or on Form1's ComboBox_Click event or some button to open up Form2?

' combo box change
Private Sub ComboBox_Click()
     Form2.TreeViewCtl1.Nodes.Clear
     ' populate nodes based on ComboBox value
End Sub

' button to second form
Private Sub btnGoToForm2_Click()
     Form2.TreeViewCtl1.Nodes.Clear
     ' populate nodes based on ComboBox value
End Sub

' second forms Load event
Private Sub Form_Load()
     TreeViewCtl1.Nodes.Clear
     ' populate nodes based on Form1.ComboBox value
End Sub
Hi Prysson,

The methods Count and Clear are applicable to the collection Nodes of the object TreeView instead of directly to the object.

You basically need to write:

If TreeView1.Nodes.Count > 0 Then
  TreeView1.Nodes.Clear
End If

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial