Treeview select/selected property

Posted on 2006-05-01
Last Modified: 2010-04-23
Hi Experts,

I am using 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
    LVL 3

    Expert Comment

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

    Author Comment

    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.
    LVL 3

    Accepted Solution

    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

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now