Back to Devexpress

Drag-and-Drop Between GridControl and Other Controls

wpf-119260-controls-and-libraries-data-grid-drag-and-drop-process-drag-and-drop-drag-and-drop-between-gridcontrol-and-other-controls.md

latest3.0 KB
Original Source

Drag-and-Drop Between GridControl and Other Controls

  • Jun 02, 2022
  • 5 minutes to read

The GridControl allows dragging records and dropping them in external controls. This topic demonstrates how to implement drag-and-drop between the GridControl and other controls that do not have a built-in drag-and-drop functionality.

The following image shows dragging records to and from the custom TextBlock :

View Example: How to implement drag-and-drop between the GridControl and other controls

Steps 1-2. Add Controls

  1. Add the GridControl to your project’s window:

  2. Add the TextBlock to your project’s window. The code sample below demonstrates the TextBlock with custom settings:

Steps 3-6. Implement Drag-and-Drop from the GridControl to the TextBlock

  1. Set the DataViewBase.AllowDragDrop property to true to enable drag-and-drop in the GridControl :

  2. Set the UIElement.AllowDrop property to true to allow dropping records in the TextBlock.

  3. Process dropped data and specify the TextBlock ‘s content:

  4. You can add actions that are performed during dragging. Use the DragDrop.DragEnter and DragDrop.DragLeave events on the TextBlock to indicate a drop target. The code sample below demonstrates how to change the TextBlock’s background color when dragging records into/out of the TextBlock:

Steps 7-9. Implement Drag-and-Drop from the TextBlock to the GridControl

  1. The TextBlock can be a drag source. Complete the following tasks to initiate a drag-and-drop operation:

  2. Now you can drag data from the TextBlock but not drop it in the GridControl. Perform the following steps to allow dropping:

  3. Complete the following actions to process dropped data:

See Also

Drag-and-Drop Options

Drag-and-Drop Between GridControl and ListBoxEdit

Drag-and-Drop Between GridControls

Drag-and-Drop Between Applications