Treeview select/selected property

Posted on 2006-05-01
Medium Priority
Last Modified: 2010-04-23
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.
Question by:MVas
  • 2
  • 2

Expert Comment

ID: 16583476
TreeView1.SelectedNode = x 'with x is the node that you want to select

Author Comment

ID: 16584153
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.

Accepted Solution

maidinhtai earned 320 total points
ID: 16586746
x is a TreeNode. For example, you have the TreeView TreeView1:
      Node1      'Index = 1
          Node7   'Index = 0. Node 7 is the childnode of node4
      Node6   'Index = 6
And you want node7 to be selected: TreeView1.SelectedNode = TreeView1.Nodes(4).Nodes(0)

Author Comment

ID: 16593331
I tried your examlpe above and it works like a charm,
thank you maidinhtai

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question