Treeview help needed

teamdad

Member
Joined
Jun 14, 2004
Messages
12
Programming Experience
Beginner
I have a Treeview with 5 nodes on it, Tc3p1 is the name & tag of the specific node I want the user to click on in my treeview to run the code below. It should show the output to the Label1 that I also have on the form. My code isn't working at all and I need a full working code example like I have done so that I can get it to work.

VB.NET:
Expand Collapse Copy
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
If Tc3p1.Selected = True Then
            Dim r As New System.Random()
            Label1.Text = r.Next(0, 9)
     End Sub
Thanking replies in advance.
 
I'm a little confused here: Selected is not even a member of TreeNode, so your code should not even compile.
Use the Is operator:

VB.NET:
Expand Collapse Copy
[COLOR=black][FONT=Courier New][COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] TreeView1_AfterSelect([COLOR=blue]ByVal[/COLOR] sender [COLOR=blue]As[/COLOR] System.Object, _
[COLOR=blue]ByVal[/COLOR] e [COLOR=blue]As[/COLOR] System.Windows.Forms.TreeViewEventArgs) [COLOR=blue]Handles[/COLOR] TreeView1.AfterSelect
    [COLOR=blue]If[/COLOR] e.Node [COLOR=blue]Is[/COLOR] Tc3p1 [COLOR=blue]Then[/COLOR]
        Text = [COLOR=maroon]"this is the node = "[/COLOR] + e.Node.Text
    [COLOR=blue]Else[/COLOR]
        Text = [COLOR=maroon]"other node selected = "[/COLOR] + e.Node.Text
    [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
[/FONT][/COLOR]
 
Back
Top