TreeView selecting nodes via code

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

    TreeView selecting nodes via code

    I'm currently using a context menu to allow the user to add, rename and
    delete nodes in a treeview control. When a node is added we give it a bogus
    name ("NewNode") and invoke the add method. We would then to then select the
    newly added node and rename it but can't figure out how to select the node
    via code.

    How do you select a node from code when you don't know the index?

    --
    Thanks
    Joe
  • Vijaye Raji

    #2
    Re: TreeView selecting nodes via code

    treeNode.Select ed = true;

    -vj

    "JoKur" <Joe@JoKur.ne t> wrote in message
    news:5E22DCF3-08F3-48A9-AE95-9EE1B110FCF3@mi crosoft.com...[color=blue]
    > I'm currently using a context menu to allow the user to add, rename and
    > delete nodes in a treeview control. When a node is added we give it a
    > bogus
    > name ("NewNode") and invoke the add method. We would then to then select
    > the
    > newly added node and rename it but can't figure out how to select the node
    > via code.
    >
    > How do you select a node from code when you don't know the index?
    >
    > --
    > Thanks
    > Joe[/color]


    Comment

    • JoKur

      #3
      Re: TreeView selecting nodes via code

      Huh?

      I'm using ...
      (In mouse down event)
      mySelectedNode = treeBlocks.GetN odeAt(e.X, e.Y);

      (In add sub)
      mySelectedNode. Nodes.Add ("New");

      where mySelectedNode is a TreeNode

      Intellisense doesn't allow mySelectedNode. Selected as you suggest. Can you
      be more specific? Also, my question still remains - how does it know which
      to select if there are many nodes? You haven't passed it any text or index?



      "Vijaye Raji" wrote:
      [color=blue]
      > treeNode.Select ed = true;
      >
      > -vj
      >
      > "JoKur" <Joe@JoKur.ne t> wrote in message
      > news:5E22DCF3-08F3-48A9-AE95-9EE1B110FCF3@mi crosoft.com...[color=green]
      > > I'm currently using a context menu to allow the user to add, rename and
      > > delete nodes in a treeview control. When a node is added we give it a
      > > bogus
      > > name ("NewNode") and invoke the add method. We would then to then select
      > > the
      > > newly added node and rename it but can't figure out how to select the node
      > > via code.
      > >
      > > How do you select a node from code when you don't know the index?
      > >
      > > --
      > > Thanks
      > > Joe[/color]
      >
      >
      >[/color]

      Comment

      • Dave

        #4
        Re: TreeView selecting nodes via code

        if treeView is of the type TreeView:

        treeView.Select edNode = mySelectedNode;

        if you want to selected the "New" node, then assign it to a variable:

        TreeNode newNode = mySelectedNode. Nodes.Add ("New");
        treeView.Select edNode = newNode;

        or:

        treeView.Select edNode = mySelectedNode. Nodes[0]; // assuming "New" has an index of 0 (zero)

        --
        Dave Sexton
        dave@www..jwaon line..com
        -----------------------------------------------------------------------
        "JoKur" <Joe@JoKur.ne t> wrote in message news:53523296-7E55-4BF4-844B-3C1A1E6984FF@mi crosoft.com...[color=blue]
        > Huh?
        >
        > I'm using ...
        > (In mouse down event)
        > mySelectedNode = treeBlocks.GetN odeAt(e.X, e.Y);
        >
        > (In add sub)
        > mySelectedNode. Nodes.Add ("New");
        >
        > where mySelectedNode is a TreeNode
        >
        > Intellisense doesn't allow mySelectedNode. Selected as you suggest. Can you
        > be more specific? Also, my question still remains - how does it know which
        > to select if there are many nodes? You haven't passed it any text or index?
        >
        >
        >
        > "Vijaye Raji" wrote:
        >[color=green]
        >> treeNode.Select ed = true;
        >>
        >> -vj
        >>
        >> "JoKur" <Joe@JoKur.ne t> wrote in message
        >> news:5E22DCF3-08F3-48A9-AE95-9EE1B110FCF3@mi crosoft.com...[color=darkred]
        >> > I'm currently using a context menu to allow the user to add, rename and
        >> > delete nodes in a treeview control. When a node is added we give it a
        >> > bogus
        >> > name ("NewNode") and invoke the add method. We would then to then select
        >> > the
        >> > newly added node and rename it but can't figure out how to select the node
        >> > via code.
        >> >
        >> > How do you select a node from code when you don't know the index?
        >> >
        >> > --
        >> > Thanks
        >> > Joe[/color]
        >>
        >>
        >>[/color][/color]


        Comment

        • JoKur

          #5
          Re: TreeView selecting nodes via code

          EXCELLENT!

          Just what I needed. Thanks Dave!


          "Dave" wrote:
          [color=blue]
          > if treeView is of the type TreeView:
          >
          > treeView.Select edNode = mySelectedNode;
          >
          > if you want to selected the "New" node, then assign it to a variable:
          >
          > TreeNode newNode = mySelectedNode. Nodes.Add ("New");
          > treeView.Select edNode = newNode;
          >
          > or:
          >
          > treeView.Select edNode = mySelectedNode. Nodes[0]; // assuming "New" has an index of 0 (zero)
          >
          > --
          > Dave Sexton
          > dave@www..jwaon line..com
          > -----------------------------------------------------------------------
          > "JoKur" <Joe@JoKur.ne t> wrote in message news:53523296-7E55-4BF4-844B-3C1A1E6984FF@mi crosoft.com...[color=green]
          > > Huh?
          > >
          > > I'm using ...
          > > (In mouse down event)
          > > mySelectedNode = treeBlocks.GetN odeAt(e.X, e.Y);
          > >
          > > (In add sub)
          > > mySelectedNode. Nodes.Add ("New");
          > >
          > > where mySelectedNode is a TreeNode
          > >
          > > Intellisense doesn't allow mySelectedNode. Selected as you suggest. Can you
          > > be more specific? Also, my question still remains - how does it know which
          > > to select if there are many nodes? You haven't passed it any text or index?
          > >
          > >
          > >
          > > "Vijaye Raji" wrote:
          > >[color=darkred]
          > >> treeNode.Select ed = true;
          > >>
          > >> -vj
          > >>
          > >> "JoKur" <Joe@JoKur.ne t> wrote in message
          > >> news:5E22DCF3-08F3-48A9-AE95-9EE1B110FCF3@mi crosoft.com...
          > >> > I'm currently using a context menu to allow the user to add, rename and
          > >> > delete nodes in a treeview control. When a node is added we give it a
          > >> > bogus
          > >> > name ("NewNode") and invoke the add method. We would then to then select
          > >> > the
          > >> > newly added node and rename it but can't figure out how to select the node
          > >> > via code.
          > >> >
          > >> > How do you select a node from code when you don't know the index?
          > >> >
          > >> > --
          > >> > Thanks
          > >> > Joe
          > >>
          > >>
          > >>[/color][/color]
          >
          >
          >[/color]

          Comment

          Working...