Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Move node in DiagramNodeCollection? (Read 2320 times)
Amosius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 75
Joined: Sep 2nd, 2010
Move node in DiagramNodeCollection?
Oct 13th, 2011 at 2:40pm
Print Post  
Hi, i would like to move a node inside my collection in Diagram.Nodes.
I tried to remove my node and insert it, but in a previous
topic you explained that insertion is not supported due to some event handlers...

Hmm... any hint how i could move one node without clearing and adding all nodes again?

Amosius
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Move node in DiagramNodeCollection?
Reply #1 - Oct 13th, 2011 at 3:03pm
Print Post  
Hi,

Try shifting the nodes in the collection by assigning them to new positions - the assignment should not trigger the built-in handlers. Here is a sample (untested) method which should do that:

Code
Select All
void MoveNode(int oldPos, int newPos)
{
	var node = d.Nodes[oldPos];
	int dir = newPos > oldPos ? 1 : -1;
	for (int i = oldPos; i != newPos; i += dir)
		d.Nodes[i] = d.Nodes[i + dir];
	d.Nodes[newPos] = node;
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Amosius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 75
Joined: Sep 2nd, 2010
Re: Move node in DiagramNodeCollection?
Reply #2 - Oct 14th, 2011 at 11:08am
Print Post  
That does the trick Smiley

Thx. Amosius
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint