Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Move selection by code (Read 1495 times)
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Move selection by code
Dec 4th, 2014 at 8:25am
Print Post  
Hello.
How can I move selection by code? In moment when user tries to move the node (Selection.Items.Count == 1) I need to add some nodes into the Selection and move all selected nodes. Now I catch the event NodeStartModifying and add necessary node by Selection.AddItem method. By only first active node moves after that.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Move selection by code
Reply #1 - Dec 4th, 2014 at 9:09am
Print Post  
Hi,

If you need dependent nodes to always follow movements of some node, you could attach them to the main node using AttachTo method. If you need to select and move only in specific circumstances, try using a Behavior class:

Code
Select All
diagram.CustomBehavior = new SelectionBehaviorEx(diagram);

class SelectionBehaviorEx : LinkShapesBehavior
{
	protected internal SelectionBehaviorEx(Diagram diagram) :
		base(diagram)
	{
	}

	public override InteractionState StartDraw(Point point)
	{
		var interaction = base.StartDraw(point);

		if (interaction.Action == Action.Modify &&
			interaction.AdjustmentHandle == 8 /* move */ &&
			interaction.CurrentItem is DiagramNode)
		{
			// select extra nodes
			Diagram.Nodes[1].Selected = true;
			return new InteractionState(Diagram.Selection,
				interaction.AdjustmentHandle, interaction.Action);
		}

		return interaction;
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Move selection by code
Reply #2 - Dec 4th, 2014 at 12:16pm
Print Post  
Yes, it works. Thank you
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint