• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

Treeview select/selected property

Hi Experts,

I am using vb.net 2005 framework2, there is a treeview in my program, what I would like to do is
click on a button and then a specific node is selected, click on a different button and a different node is selected.
I did some searching on ee but found questions relating to the selected property of the treeview which
i cannot find, i did find a select property but it doesnt allow to select nodes,

any help
would be appreciated.
thank you.
0
MVas
Asked:
MVas
  • 2
  • 2
1 Solution
 
maidinhtaiCommented:
TreeView1.SelectedNode = x 'with x is the node that you want to select
0
 
MVasAuthor Commented:
hi maidinhtai

I tried the code you posted as follows:

treeview1.SelectedNode = 0 'It threw the following error
Value of type 'Integer' cannot be converted to 'System.Windows.Forms.TreeNode'.

I then tried

Dim mynode As New System.Windows.Forms.TreeNode

mynode.Index = 0
treeview1.SelectedNode = mynode

this won't build because property "Index" is read-only

can you help me finding what "x" needs to be in your example.
0
 
maidinhtaiCommented:
x is a TreeNode. For example, you have the TreeView TreeView1:
      Node0
      Node1      'Index = 1
      Node2
      Node3
      Node4
          Node7   'Index = 0. Node 7 is the childnode of node4
          Node8
      Node5
      Node6   'Index = 6
And you want node7 to be selected: TreeView1.SelectedNode = TreeView1.Nodes(4).Nodes(0)
0
 
MVasAuthor Commented:
I tried your examlpe above and it works like a charm,
thank you maidinhtai
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now