Back to Devexpress

Drag-and-Drop Options

wpf-119241-controls-and-libraries-data-grid-drag-and-drop-drag-and-drop-options.md

latest5.1 KB
Original Source

Drag-and-Drop Options

  • Jan 05, 2024
  • 3 minutes to read

The GridControl has a set of properties and events that allow you to control drag-and-drop operations at different stages.

Common

Use the following properties to enable drag-and-drop operations:

PropertyDescription
DataViewBase.AllowDragDropGets or sets whether an end user can drag and drop grid view’s records.
DataViewBase.AllowSortedDataDragDropGets or sets whether an end user can drag and drop sorted or grouped data.

The GridControl with the drag-and-drop functionality enabled requires 2 mouse clicks to activate a cell editor and 3 clicks to open a drop-down editor. You can set the DataViewBase.EditorShowMode property to MouseDownFocused or MouseUp to reduce the number of clicks.

The Beginning of the Drag-and-drop Operation

You can prevent the drag-and-drop operation or customize the dragged data:

EventDescription
DataViewBase.StartRecordDragOccurs when a drag-and-drop operation is started. You can use this event to modify dragged data or forbid dragging specific records.

The Dragging Process

You can specify how your source and target grids behave during the drag-and-drop operation, and customize the drop hint and marker elements’ appearance:

PropertyDescription
DataViewBase.AutoExpandOnDragGets or sets whether dragging records over a collapsed group automatically expands this group.
DataViewBase.AutoExpandDelayOnDragGets or sets the delay after which the collapsed group is expanded, in milliseconds.
DataViewBase.AllowScrollingOnDragGets or sets whether dragging records to the edges of the grid’s view automatically activates scrolling.
DataViewBase.ShowDragDropHintGets or sets whether the drag-and-drop hint is displayed when dragging a record.
DataViewBase.ShowTargetInfoInDragDropHintGets or sets whether the drag-and-drop hint shows information about a drop target.
DataViewBase.DragDropHintTemplateGets or sets the template that defines the drag-and-drop hint‘s presentation.
DataViewBase.DropMarkerTemplateGets or sets the template that defines the drop marker‘s presentation.
EventDescription
DataViewBase.DragRecordOverOccurs continuously while a record is dragged within the drop target’s boundary. You can use this event to check dragged data availability, deny a drop operation over specific records, or set a drop position.
DataViewBase.GiveRecordDragFeedbackOccurs continuously during a drag-and-drop operation and enables the drop source to give feedback to the user.
DataViewBase.ContinueRecordDragOccurs when there is a change in the keyboard or mouse button states during a drag-and-drop operation, and enables the drop source to cancel the drag-and-drop operation depending on the key/button states.

The End of the Drag-and-drop Operation

You can reorder items, customize dropped data, and prevent removing the dragged items from the source grid:

EventDescription
DataViewBase.DropRecordOccurs when a record is dropped on the target element. You can use this event to process dropped data.
DataViewBase.CompleteRecordDragDropOccurs when a drag-and-drop operation is completed. You can use this event to cancel removing records after dropping or add additional actions.

Tip

For the ListBoxEdit, you can use the ListBoxDragDropBehavior class’s attached properties and events. Refer to the Drag-and-Drop Between GridControl and ListBoxEdit topic for more information.