Link to home
Start Free TrialLog in
Avatar of Prysson
Prysson

asked on

Treeview method question

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.

Avatar of joghall
joghall

what code do you have already?

Jon
Avatar of Prysson

ASKER

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.

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
ASKER CERTIFIED SOLUTION
Avatar of cparlanti
cparlanti

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial