Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Programmingly Change treeview indexes

Programmingly Change treeview indexes

Scheduled Pinned Locked Moved C#
questiondatabasetutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ronni Marker
    wrote on last edited by
    #1

    I have a Treeview where I want to programmingly change index, but aparently that is a challenge that is more than I can do on my own. My treeview looks like this Node1(Groups) +Child1 +Child2 +Child3 Node2(New node to insert) Node3(Search Result) Above is the wanted treeview layout. I have manually added Node1 with child nodes, and Node3. Now I wanted to add the node, as in this example called Node2, but how do i add this node, sort the Node rows and still make sure that Node1 stay in top and Node3 always is at the end? Any taker on this idea? I had initially thought to change treeview1.nodes["Node1"].index = 0 and treeview.nodes["Node3"].index = treeview1.lastindex, but that would not work, as index is read only.

    L 1 Reply Last reply
    0
    • R Ronni Marker

      I have a Treeview where I want to programmingly change index, but aparently that is a challenge that is more than I can do on my own. My treeview looks like this Node1(Groups) +Child1 +Child2 +Child3 Node2(New node to insert) Node3(Search Result) Above is the wanted treeview layout. I have manually added Node1 with child nodes, and Node3. Now I wanted to add the node, as in this example called Node2, but how do i add this node, sort the Node rows and still make sure that Node1 stay in top and Node3 always is at the end? Any taker on this idea? I had initially thought to change treeview1.nodes["Node1"].index = 0 and treeview.nodes["Node3"].index = treeview1.lastindex, but that would not work, as index is read only.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      don't use Add, but use InsertAt

      R 1 Reply Last reply
      0
      • L Lost User

        don't use Add, but use InsertAt

        R Offline
        R Offline
        Ronni Marker
        wrote on last edited by
        #3

        Ofcause! Thanks buddy. Is there any way to move a node to a specific index? ie when I do a sort, I can't "lock" some nodes, so have to move them back to the index location again.

        D 1 Reply Last reply
        0
        • R Ronni Marker

          Ofcause! Thanks buddy. Is there any way to move a node to a specific index? ie when I do a sort, I can't "lock" some nodes, so have to move them back to the index location again.

          D Offline
          D Offline
          Dan Mos
          wrote on last edited by
          #4

          Create a temporary treeNode, set it to the one you want to move, remove it from the old location and insert it at the desired location. OK heres a posible pseudo code/steps:

          1. Create a temp TreeNodeCollection :
            TreeNodeCollection tmp = (TreeNodeCollection)treeView1.Nodes["myNode"].Clone(); //or
            TreeNodeCollection tmp = (TreeNodeCollection)treeView1.Nodes[idx].Clone();

          2. Remove the node from the old location
            treeView1.Nodes.RemoveAt(idx);

          3. Insert it at the desired location
            treeView1.Nodes.Insert(desired_Idx, tmp[0]);
            //also you could use a for/foreach to insert the childnodes of the removed node if any

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups