Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Drag-and-Drop Between GridControl and ListBoxEdit

  • 2 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 the ListBoxEdit.

The following image shows dragging records to and from the ListBoxEdit:

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

Follow the steps below to implement drag-and-drop between the GridControl and the ListBoxEdit:

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

    <dxg:GridControl Name="gridControl">
       <!---->
       <dxg:GridControl.View>
          <dxg:TableView />
       </dxg:GridControl.View>
    </dxg:GridControl>
    
    <dxe:ListBoxEdit Name="listBoxEdit" />
    
  2. Activate drag-and-drop operations in the added controls:

    <dxg:GridControl Name="gridControl">
       <!---->
       <dxg:GridControl.View>
          <dxg:TableView AllowDragDrop="True" />
       </dxg:GridControl.View>
    </dxg:GridControl>
    
    <dxe:ListBoxEdit Name="listBoxEdit" 
       dx:ListBoxDragDropBehavior.AllowDragDrop="True" />
    
  3. Now you can drag records but not drop them in another control. Do the following steps to allow dropping:

    <dxg:GridControl Name="gridControl">
       <!---->
       <dxg:GridControl.View>
          <dxg:TableView AllowDragDrop="True" DragRecordOver="OnDragRecordOver" />
       </dxg:GridControl.View>
    </dxg:GridControl>
    
    <dxe:ListBoxEdit Name="listBoxEdit" 
       dx:ListBoxDragDropBehavior.AllowDragDrop="True" 
       dx:ListBoxDragDropBehavior.DragRecordOver="OnDragRecordOver" />
    
    void OnDragRecordOver(object sender, DragRecordOverEventArgs e) {
       if (e.IsFromOutside && typeof(Employee).IsAssignableFrom(e.GetRecordType())) {
          e.Effects = DragDropEffects.Move;
          e.Handled = true;
       }
    }
    
  4. The controls in the demonstrated example have the same data source type. If data source types are different:

    See the DataViewBase.DropRecord event implementation in the Drag-and-Drop Between GridControl and Other Controls topic to learn how to modify the dragged data.

See Also