10676 : Visual feedback on drag over

Question

I like to use Drag & Drop to reorder rows in a Grid. Do you have a Example or a Idee about the best way, to give the user a visual feedback about the possible insert point while moving the mouse over the rows in Drag-Mode?

MS Excel, for example, displays a horizontal line between the possible destinations if you drag rows.

Answer

I guess the standard way is to signal feedback by using the drop icon, and maybe have it changed if the drop means different things. Like in Explorer when a plus is drawn for copy and an arrow is shown for move.

If you want to do something in the grid upon dragover, you can simply collect all the necessary info in the DragOver event (cell, gridNode or what you have) keep this info in member variables, set a flag in a member variable stating that it is DragOverFeedBack-time. Call Grid.Refresh (forcing a redraw). An implement the OnGridPaintForeground to draw “something” on the grid to let the user understand what can happen once he lets go of the mouse.

Or you can simply change the CellLayout property of the effected cells within the DragOver event, to something that sticks out.

10620 : Drag in grid

Question

Can you tell me if it is possible to implement drag and drop of rows in the grid area?  I can’t see any built-in support but any advice would be much appreciated, we need to be able to drag rows within a “sibling” array and also between “parents”

Answer

You can do drag & drop. In the general download look for a sample called Gantt_GridDragDrop.

You need to start the drag in OnMouseDown, and decide what to do in OnDragDrop…


		Private Sub gantt1_OnGridMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
		  If Not gantt1.Grid.GridStructure.FocusedCell Is Nothing Then
			gantt1.Grid.StopRowResize()
			  gantt1.DoDragDrop(gantt1.Grid.GridStructure.FocusedCell.Content.Value.ToString(), DragDropEffects.All)
		  End If
		End Sub

		Private Sub gantt1_OnGridDragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
		  ' Drag drop events return screen coordinates. 
		  ' You must convert it to a Client coordinate before using it in GTP.NET
		  Dim localpoint As Point=gantt1.Grid.PointToClient(New Point(e.X,e.Y))
		  Dim cell As Cell=gantt1.Grid.GridStructure.CellFromXY(localpoint.X,localpoint.Y)
		  If Not cell Is Nothing AndAlso Not cell.Node.ParentNode Is Nothing AndAlso Not gantt1.Grid.GridStructure.FocusedCell Is Nothing Then
				gantt1.Grid.GridStructure.FocusedCell.Node.MoveNode(cell.Node.ParentNode,cell.Node.Index)
		  End If
		End Sub

		Private Sub gantt1_OnGridDragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
			If e.Data.GetDataPresent(DataFormats.Text) Then
				e.Effect = DragDropEffects.Move
			End If
		End Sub

		Private Sub gantt1_OnGridDragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)

			If e.Data.GetDataPresent(DataFormats.Text) Then
				e.Effect = DragDropEffects.Move
			Else
				e.Effect = DragDropEffects.None
			End If
		End Sub

       	Private Sub PrepareEvents()

	  AddHandler gantt1.OnGridDragDrop, AddressOf gantt1_OnGridDragDrop
	  AddHandler gantt1.OnGridDragEnter, AddressOf gantt1_OnGridDragEnter
	  AddHandler gantt1.OnGridDragOver, AddressOf gantt1_OnGridDragOver
	  AddHandler gantt1.OnGridMouseDown, AddressOf gantt1_OnGridMouseDown

	End Sub