Results 1 to 7 of 7

Thread: how to check if there's a selected node in the treeview (resolved)

  1. #1

    Thread Starter
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    how to check if there's a selected node in the treeview (resolved)

    maybe this is simple but i'm in a hurry and i have no idea about this in treeview. I need to know how to check if there is there is selected node in the treeview.
    Like in the listview is like this. lstProperty.SelectedItems.Count > 0 to determine you select 1 item on it, just don't know what is the equivalent in the treeview on selecting a node.

    Thanks in advance.
    Last edited by fret; Nov 24th, 2004 at 01:31 AM.

  2. #2
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494
    Try
    VB Code:
    1. Treeview1.SelectedNode
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  3. #3

    Thread Starter
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    i've already tried that but seems not working.

  4. #4
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494
    Can you post the code that you're using?

    The selectednode should only return a single node object rather than a collection like the listview. Treeviews only allow single selection whereas a listview provides an option to multiselect.
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  5. #5

    Thread Starter
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    ok i figure it out lil thanks for the advice, but my problem now is this. I have a parent node called "node0" and has a child "node1". When i click a button i want "node0" to appear in a textbox seems okey, but my concern is when i select "node1" it appears in the textbox as "node1" and i want it appear as "node0" which is the parent of the "node1".

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         If TreeView1.SelectedNode.Parent.IsSelected Then 'Object reference not set to an instance of an object
    3.             TextBox1.Text = TreeView1.SelectedNode.Text
    4.         Else
    5.             TextBox1.Text = TreeView1.SelectedNode.Parent.Text 'this work if the child node is selected and it appears in the textbox the parent node
    6.         End If
    7.     End Sub

    i think my code is wrong but i need some help to get in the right way.

  6. #6

    Thread Starter
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    hey does anyone knows this?
    need some help here

  7. #7

    Thread Starter
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    nevermind i figured it out by myself.
    this work.
    VB Code:
    1. TreeView1.SelectedNode.Parent Is Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width