Results 1 to 4 of 4

Thread: TreeView control question

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    LA
    Posts
    57

    Question TreeView control question

    Hello Guys,

    How can I check if the TreeView Root is selected?

    Thank you.


  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Does this help?
    VB Code:
    1. If TreeView1.SelectedNode Is TreeView1.Nodes(0) Then
    2. 'Do something here
    3. End If
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    LA
    Posts
    57
    Thank for the response

    Its works for fist root but what if I have more then one Root or sub Root
    How can I check if on of them is selected?

    Thank you Again.

  4. #4
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hmm. I guess you'd have to check each node manually.
    If the nodes are added to the tree dynamically, i would set their tag property to something identifiable. Then maybe you could make a select case.
    VB Code:
    1. Select Case TreeView1.SelecteNode.Tag.ToString
    2.     Case "WhatEver"
    3.         'Do something here
    4.     Case "WhatDoIKnow"
    5.         'Do something else here
    6. End Select



    If you are goint to manipulate an object associated with the node, then just set the object to the tag property.
    Then you don't have to worry about which node is selected. You can just use the object straight away.
    VB Code:
    1. 'Add Nodes similiar to this.
    2. Dim N as New TreeNode("NodeText")
    3. N.Tag=MyObject
    4. TreeView1.Nodes.Add(N)
    5.  
    6. 'Then all you have to do is this:
    7. Dim M as MyObjectType
    8. M=DirectCast(TreeView1.SelectedNode.Tag,MyObjectType)
    9. 'You will now have access to all the relevant properties and methods of the object type.

    I hope I'm making some sense
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

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