Results 1 to 5 of 5

Thread: How Can You Change The Selected Index Of A Treeview Control

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    121

    How Can You Change The Selected Index Of A Treeview Control

    How do I change the selected index/item of a treeview control?

    I tried tv.selectedindex = 5 but it says its read only.
    I also tried tv.Nodes[5].IsSelected = true; but that does not work either

    thanks in advance

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How Can You Change The Selected Index Of A Treeview Control

    You go to the help documentation for the TreeView class, go to the member listing topic, look down the list of properties until you come to "SelectedNode" and read the following description:
    Gets or sets the tree node that is currently selected in the tree view control.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: How Can You Change The Selected Index Of A Treeview Control

    that does not work form me:
    this code:
    Code:
    TreeNode tmpNode=GetProvinceNode(iProv);
    if (iCit!=0)		
    	tmpNode=GetCityNode(tmpNode,iCit);
    tmpNode.EnsureVisible();
    tvwHierarchy.SelectedNode=tmpNode;
    do ensure the node is visible, but does not select it.
    I also wrote some code to figure out the index of the node (yes, got the right index), but still no luck. The node are visible, but selected? huh uh!

    any ideas?
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  4. #4
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: How Can You Change The Selected Index Of A Treeview Control

    ooops...did not see "ShowSelection" property
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How Can You Change The Selected Index Of A Treeview Control

    Quote Originally Posted by StrangerInBeijing
    ooops...did not see "ShowSelection" property
    Is that anything like the HideSelection property?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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