Hello Guys,
How can I check if the TreeView Root is selected?
Thank you.
:confused:
Printable View
Hello Guys,
How can I check if the TreeView Root is selected?
Thank you.
:confused:
Does this help?
VB Code:
If TreeView1.SelectedNode Is TreeView1.Nodes(0) Then 'Do something here End If
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.
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:
Select Case TreeView1.SelecteNode.Tag.ToString Case "WhatEver" 'Do something here Case "WhatDoIKnow" 'Do something else here 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:
'Add Nodes similiar to this. Dim N as New TreeNode("NodeText") N.Tag=MyObject TreeView1.Nodes.Add(N) 'Then all you have to do is this: Dim M as MyObjectType M=DirectCast(TreeView1.SelectedNode.Tag,MyObjectType) 'You will now have access to all the relevant properties and methods of the object type.
I hope I'm making some sense :p