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
  1. Home
  2. General Programming
  3. C#
  4. how to maintain the same order in a treeview control where the nodes comes from other treeview. [modified]

how to maintain the same order in a treeview control where the nodes comes from other treeview. [modified]

Scheduled Pinned Locked Moved C#
helpxmltutorial
2 Posts 2 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.
  • G Offline
    G Offline
    Gonxh Aniket
    wrote on last edited by
    #1

    Hi, In my windows application, I have 2 treeview controls, say trvw1 and trvw2. I populate trvw1 from XML file. Selected nodes will be shifted to trvw2. When I select node1 after selecting node3 trvw2 appears as below. trvw1 trvw2 ------ ------ node1 node3 node11 node31 node12 node32 node2 node1 node21 node11 node3 node12 node31 node32 But in trvw2, node1 should appear above the node3 as it appears in the trvw1. The order of nodes should not get disturbed in trvw2 . Could you help me to solve this problem. Thanks in advance..

    modified on Wednesday, February 4, 2009 12:34 AM

    M 1 Reply Last reply
    0
    • G Gonxh Aniket

      Hi, In my windows application, I have 2 treeview controls, say trvw1 and trvw2. I populate trvw1 from XML file. Selected nodes will be shifted to trvw2. When I select node1 after selecting node3 trvw2 appears as below. trvw1 trvw2 ------ ------ node1 node3 node11 node31 node12 node32 node2 node1 node21 node11 node3 node12 node31 node32 But in trvw2, node1 should appear above the node3 as it appears in the trvw1. The order of nodes should not get disturbed in trvw2 . Could you help me to solve this problem. Thanks in advance..

      modified on Wednesday, February 4, 2009 12:34 AM

      M Offline
      M Offline
      MartyExodus
      wrote on last edited by
      #2

      Well, a horribly inefficient, but likewise easy method would be to use a BubbleSort, referring back to original TreeNode.

      bool done = false;
      int length = trvw2.Nodes.Count;

      while(!done)
      {
      done = true;
      for(int i = 1; i<length;> {
      if(trvw1.Nodes.IndexOf(trvw2.Nodes[i])<trvw1.Nodes.IndexOf(trvw2.Nodes[i-1]))
      {
      done = false;
      //INSERT NODE SWAP CODE
      }
      }
      }

      I would include the "NODE SWAP CODE," but I'm not anywhere that I can check syntax, so yeah. Sorry if it doesn't work or if there are small errors - I'm working entirely off of memory. EDIT: Fixed typos.

      There is no knowledge that is not power. - Mortal Kombat

      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