Page Index Toggle Pages: 1 [2]  Send TopicPrint
Hot Topic (More than 10 Replies) Drag&Drop problem (Read 11026 times)
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drag&Drop problem
Reply #15 - Jun 20th, 2007 at 3:57pm
Print Post  
Flowchart.NET never calls DoDragDrop, so there shouldn't be any drag-and-drop operation started when you drag a node. Are you sure DoDragDrop is not called from your FlowChart.MouseDown event handler, as well as from the gridview MouseDown handler?

Stoyan
  
Back to top
 
IP Logged
 
mjweyland
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Apr 2nd, 2007
Re: Drag&Drop problem
Reply #16 - Jun 20th, 2007 at 3:59pm
Print Post  
positive. 

The odd thing is that the same code for dropping an object in from either a list box or a grid view is executed.

However if the item dropped in is from a listbox the issue doesn't arise.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drag&Drop problem
Reply #17 - Jun 20th, 2007 at 4:06pm
Print Post  
I am not sure if I am entirely grasping the situation 8) So there are three possible drag sources - a list view, a grid view and the flowchart. When dragging from the list view, everything is ok. When dragging from the grid view, something gets broken and consequent drag-and-drop operations started from the flowchart replicate only the first grid-view item copied? Is that right? Could you post here all relevant event handlers that have something to do with drag-and-drop?

Stoyan
  
Back to top
 
IP Logged
 
mjweyland
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Apr 2nd, 2007
Re: Drag&Drop problem
Reply #18 - Jun 20th, 2007 at 4:14pm
Print Post  
Yes you have it.  Here is the code.

GridView Event code
Code
Select All
	  '//Get the gridview for the gvGenericLibrary
	  Dim gv As DevExpress.XtraGrid.Views.Grid.GridView = TryCast(Me.gvGenericLibrary.MainView, DevExpress.XtraGrid.Views.Grid.GridView)

	  '//Ensure that the user is clicking on a datarow
	  If gv.FocusedRowHandle < 0 Then Exit Sub

	  Try
		'//Update user form
		StartWorking("Building Component")

		'// Fetch the information from the library and create respective node
		Dim _n As FlowChartItems.NodeBase = ARSFactory.GetNode(gv.GetDataRow(gv.FocusedRowHandle).Item("ID").ToString)
		DoDragDrop(New NodeDragItem(_n.Copy), DragDropEffects.Copy)

	  Catch ex As Exception
 My.Application.Log.WriteException(ex)
		MessageBox.Show(ex.Message, "Error building component", MessageBoxButtons.OK, MessageBoxIcon.Error)

	  Finally
		'// change form to non-working state
		StopWorking()
	  End Try
 



List Box handler
Code
Select All
    Private Sub ilbComponents_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ilbComponents.MouseDown
	  DoDragDrop(New NodeDragItem(Me.ilbComponents.SelectedIndex), DragDropEffects.Copy)
    End Sub 



Drop Event on Flowchart
Code
Select All
    Private Sub fcMain_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles fcMain.DragDrop

	  Try
		_parent.StartWorking("Creating Node")
		If e.Data.GetDataPresent(NodeDragItem._GetType()) Then

		    Dim sdi As NodeDragItem = DirectCast(e.Data.GetData(NodeDragItem._GetType()), NodeDragItem)

		    If sdi.Index >= 0 And sdi.Index < NodeTemplates.Nodes.Count Then
			  Dim p As Point = fcMain.PointToClient(New Point(e.X, e.Y))
			  Dim pt As PointF = fcMain.ClientToDoc(New Point(p.X, p.Y))
			  'test to see if the nodedragitem is storing an ARS node to copy
			  Dim _n As FlowChartItems.NodeBase
			  If Not sdi.Node Is Nothing Then
				_n = sdi.Node
			  Else
				_n = ARSFactory.GetNewNode(NodeTemplates.Nodes(sdi.Index + 1).GetType.Name.ToString)
			  End If
			  DrawNode(_n, pt.X, pt.Y)
		    End If

		End If
	  Catch ex As Exception
		My.Application.Log.WriteException(ex)
		MessageBox.Show("Error creating node", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
	  Finally
		_parent.StopWorking()
	  End Try
    End Sub
 



The drawnode event just creates an instance of the node in the workspace.  No Drag or Drop events are ffired here.

DragOver Event
Code
Select All
    Private Sub fcMain_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles fcMain.DragOver
	  If e.Data.GetDataPresent(NodeDragItem._GetType()) Then
		e.Effect = DragDropEffects.Copy
	  Else
		e.Effect = DragDropEffects.None
	  End If
    End Sub
 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drag&Drop problem
Reply #19 - Jun 21st, 2007 at 5:23am
Print Post  
Are you sure gv.FocusedRowHandle refers to the item under the mouse cursor at the time when Gridview.MouseDown is raised? If the grid view first raises MouseDown, and selects the row in the OnMouseUp method, then FocusedRowHandle would just always point to the same item, since calling DoDragDrop prevents the drag source from receiving a mouse-up event. Also, I believe the recommended method to start drag-and-drop is from MouseMove handler, after the mouse has moved at least 
SystemInformation.DragSize pixels since MouseDown has been raised. That ensures that users will be able to click and select an item, without accidentally starting drag-and-drop.

Stoyan
  
Back to top
 
IP Logged
 
mjweyland
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Apr 2nd, 2007
Re: Drag&Drop problem
Reply #20 - Jun 21st, 2007 at 12:43pm
Print Post  
Thanks for the suggestion this resolved the issue.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send TopicPrint