How to select treenode in treeview by name?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wes

    How to select treenode in treeview by name?

    I have a treeview that I am continually added nodes to. Each time a new node
    is added I would like to select that node.

    Is this possible? I have looked at selectedNode, but I don't know how to
    point that at a given node using the nodes name.

    I have the nodes name and it's parents name. Does anyone know a good way to
    find the node based on this information?

    Thanks a bunch.
  • Mattias Sjögren

    #2
    Re: How to select treenode in treeview by name?

    [color=blue]
    >I have a treeview that I am continually added nodes to. Each time a new node
    >is added I would like to select that node.[/color]

    The easiest way to do that is probably

    TreeNode node = // ... create node via Nodes.Add or whatever
    yourTreeView.Se lectedNode = node;

    [color=blue]
    >Is this possible? I have looked at selectedNode, but I don't know how to
    >point that at a given node using the nodes name.
    >
    >I have the nodes name and it's parents name. Does anyone know a good way to
    >find the node based on this information?[/color]

    TreeNodes don't have names. I'm not sure if you mean the name of the
    variable you use to reference the nodes or the Text property of the
    node. Either way, it's probably easier to do as above.



    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    • Wes

      #3
      Re: How to select treenode in treeview by name?

      Thanks for the response.

      When I said name before I did mean the treeNode.text and treeNode.parent .text.

      My question is how do I use the above mentioned information to get a new
      treeNode object that I can select.

      For Example

      TreeNode myTreeNode = "how do I create treenode based on parent.text and
      node.text?"
      myTreeView.sele ctedNode = myTreeNode;


      "Mattias Sjögren" wrote:
      [color=blue]
      >[color=green]
      > >I have a treeview that I am continually added nodes to. Each time a new node
      > >is added I would like to select that node.[/color]
      >
      > The easiest way to do that is probably
      >
      > TreeNode node = // ... create node via Nodes.Add or whatever
      > yourTreeView.Se lectedNode = node;
      >
      >[color=green]
      > >Is this possible? I have looked at selectedNode, but I don't know how to
      > >point that at a given node using the nodes name.
      > >
      > >I have the nodes name and it's parents name. Does anyone know a good way to
      > >find the node based on this information?[/color]
      >
      > TreeNodes don't have names. I'm not sure if you mean the name of the
      > variable you use to reference the nodes or the Text property of the
      > node. Either way, it's probably easier to do as above.
      >
      >
      >
      > Mattias
      >
      > --
      > Mattias Sjögren [MVP] mattias @ mvps.org
      > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
      > Please reply only to the newsgroup.
      >[/color]

      Comment

      Working...