how to maintain the same order in a treeview control where the nodes comes from other treeview. [modified]
-
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
-
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
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