Setting Treeview Index

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

    #1

    Setting Treeview Index

    I have tried the following code to set the index for a
    node. It seems to work when I use the root node index of
    0. When I try a number greater than 0 I get an out of
    range error. I made sure that the tree was expanded, as
    well.

    treeView1.Focus ();
    treeView1.Selec tedNode = treeView1.Nodes[1];

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Setting Treeview Index

    Kelvin,

    How many nodes are there under the root? I think that the Nodes that
    are being exposed is the top level of nodes, and not all of the nodes in the
    tree. If you have only one node at the root, then this would definitely
    fail.

    Hope this helps.


    "Kelvin Bryant" <kelvinabryant@ hotmail.com> wrote in message
    news:0b3901c398 a9$20c210b0$310 1280a@phx.gbl.. .[color=blue]
    > I have tried the following code to set the index for a
    > node. It seems to work when I use the root node index of
    > 0. When I try a number greater than 0 I get an out of
    > range error. I made sure that the tree was expanded, as
    > well.
    >
    > treeView1.Focus ();
    > treeView1.Selec tedNode = treeView1.Nodes[1];
    >[/color]


    Comment

    • Michael A. Covington

      #3
      Re: Setting Treeview Index


      "Kelvin Bryant" <kelvinabryant@ hotmail.com> wrote in message
      news:0b3901c398 a9$20c210b0$310 1280a@phx.gbl.. .[color=blue]
      > I have tried the following code to set the index for a
      > node. It seems to work when I use the root node index of
      > 0. When I try a number greater than 0 I get an out of
      > range error. I made sure that the tree was expanded, as
      > well.
      >
      > treeView1.Focus ();
      > treeView1.Selec tedNode = treeView1.Nodes[1];[/color]

      Note that treeView1.Nodes is only the list of nodes branching off the root;
      not all the nodes in the entire tree.

      treeView1.Nodes[1].Nodes is the list of nodes that branch off node 1, and so
      forth. It's a recursive data structure.


      Comment

      • Guest's Avatar

        #4
        Re: Setting Treeview Index

        Yes, you are on to something! My structure is as such:
        Root Node
        Parent Node 1
        Child Node 1
        Child Node 2
        Child Node 3
        Parent Node 2
        Child Node 1
        Child Node 2
        Blah Blah Blah[color=blue]
        >-----Original Message-----
        >Kelvin,
        >
        > How many nodes are there under the root? I think[/color]
        that the Nodes that[color=blue]
        >are being exposed is the top level of nodes, and not all[/color]
        of the nodes in the[color=blue]
        >tree. If you have only one node at the root, then this[/color]
        would definitely[color=blue]
        >fail.
        >
        > Hope this helps.
        >
        >
        >"Kelvin Bryant" <kelvinabryant@ hotmail.com> wrote in[/color]
        message[color=blue]
        >news:0b3901c39 8a9$20c210b0$31 01280a@phx.gbl. ..[color=green]
        >> I have tried the following code to set the index for a
        >> node. It seems to work when I use the root node index of
        >> 0. When I try a number greater than 0 I get an out of
        >> range error. I made sure that the tree was expanded, as
        >> well.
        >>
        >> treeView1.Focus ();
        >> treeView1.Selec tedNode = treeView1.Nodes[1];
        >>[/color]
        >
        >
        >.
        >[/color]

        Comment

        Working...