Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Drag and drop rows from a TableNode (Read 4062 times)
brianh
YaBB Newbies
*
Offline



Posts: 30
Joined: Jul 1st, 2008
Drag and drop rows from a TableNode
Jul 1st, 2008 at 4:23pm
Print Post  
I need to be able to drag a row form one TableNode and drop it in another, but I don't see the required events for the TableNode class.  Sad

I have derived a new class from TableNode and hooked into the parent diagram view's mouse events in order to implement this behavior, but it's fiddly and doesn't work perfectly (e.g. sometime a selection rectangle gets drawn after the drop).

Is there a better way to do this, or failing that, how can I stop the selection rectangle from being drawn and still allow the user to select a node by clicking on it?

Thanks.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drag and drop rows from a TableNode
Reply #1 - Jul 1st, 2008 at 6:21pm
Print Post  
If you are using the default DiagramView.Behavior and you don't need to draw links between tables, you could handle LinkCreating, call args.CancelDrag(), and begin the drag-and-drop operation. Another option is to set Behavior = DoNothing from the MouseDown handler when you detect the mouse is over a row.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
brianh
YaBB Newbies
*
Offline



Posts: 30
Joined: Jul 1st, 2008
Re: Drag and drop rows from a TableNode
Reply #2 - Jul 2nd, 2008 at 9:07am
Print Post  
Thanks Stoyan,

I want to change the cursor when the mouse is over a draggable row, so I think I'll go with your second suggestion and change the behavior (and the cursor) when the mouse is over the row.

But when I change the behavior back to "Modify" after the mouse moves off the row, how do I get the view to set the cursor back to what it should be (which obviously depends on it's current location)?  Is there a way to force the view to update the cursor immediately?

Thanks.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drag and drop rows from a TableNode
Reply #3 - Jul 2nd, 2008 at 9:21am
Print Post  
Hi Brian,

The DiagramView tracks the mouse position context and should revert to the expected cursor automatically.

Stoyan
  
Back to top
 
IP Logged
 
brianh
YaBB Newbies
*
Offline



Posts: 30
Joined: Jul 1st, 2008
Re: Drag and drop rows from a TableNode
Reply #4 - Jul 2nd, 2008 at 10:16am
Print Post  
Hi Stoyan,

I'm processing the mouse move events for the diagram view, and when the mouse moves over a row I change the view's behavior to DoNothing.  I then set the current cursor, the view's Cursor property and the view's CurrentCursor property all to the cursor I want, but it still doesn't change! :S  Am I missing something?

Brian
  
Back to top
 
IP Logged
 
brianh
YaBB Newbies
*
Offline



Posts: 30
Joined: Jul 1st, 2008
Re: Drag and drop rows from a TableNode
Reply #5 - Jul 2nd, 2008 at 10:59am
Print Post  
Hi Stoyan,

I got the cursor working by changing the view's PointerCursor to the one I want, is this the correct way to do it?

Thanks.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drag and drop rows from a TableNode
Reply #6 - Jul 2nd, 2008 at 11:02am
Print Post  
Hi Brian,

Actually CurrentCursor lets you override the mouse cursor only while an item is being modified. Otherwise, the view uses the cursor specified by the Behavior object's SetMouseCursor method. For the time being, you can implement that by using a custom Behavior object:

Code
Select All
public class MyBehavior : LinkTablesBehavior
{
	public MyBehavior(DiagramView view) : base(view)
	{
	}

	public override InteractionState StartDraw(PointF point)
	{
		if (OverDraggableRow(point))
			return null;

		return base.StartDraw(point);
	}

	public override CursorHint SetMouseCursor(PointF point, out bool startInteraction)
	{
		if (OverDraggableRow(point))
		{
			DiagramView.CurrentCursor = Cursors.Help;
			startInteraction = false;
			return CursorHint.DontChange;
		}

		return base.SetMouseCursor(point, out startInteraction);
	}

	private bool OverDraggableRow(PointF point)
	{
		int row = -1, col = -1;
		TableNode table = Diagram.GetNodeAt(point) as TableNode;
		return table != null && table.CellFromPoint(point, ref row, ref col) && row == 2;
	}
}
 



We'll try to make that easier in the next release, perhaps by extending the CurrentCursor feature to allow setting it when there isn't any item being modified.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drag and drop rows from a TableNode
Reply #7 - Jul 2nd, 2008 at 11:05am
Print Post  
Setting PointerCursor should work too, as long as you are sure the current Behavior object returns CursorHint.Pointer at the current position. I suppose that's true for DoNothing.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drag and drop rows from a TableNode
Reply #8 - Jul 2nd, 2008 at 11:09am
Print Post  
If you decide to use the custom Behavior implementation, you could start the drag-and-drop operation in the StartDraw override, just before returning null. To make the control use your class, set diagramView.CustomBehavior = new MyBehavior(diagramView).

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
brianh
YaBB Newbies
*
Offline



Posts: 30
Joined: Jul 1st, 2008
Re: Drag and drop rows from a TableNode
Reply #9 - Jul 2nd, 2008 at 11:24am
Print Post  
Hi Stoyan,

The custom Behavior method looks interesting, I'll give it a try.

Thanks for all your help.

Brian
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint