Back to Devexpress

DragDropEvents.BeginDragDrop Event

windowsforms-devexpress-dot-utils-dot-dragdrop-dot-dragdropevents-4dfedb77.md

latest4.1 KB
Original Source

DragDropEvents.BeginDragDrop Event

Occurs when a drag-and-drop operation is initiated.

Namespace : DevExpress.Utils.DragDrop

Assembly : DevExpress.Utils.v25.2.dll

NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core

Declaration

csharp
[DXCategory("DragDrop")]
public event BeginDragDropEventHandler BeginDragDrop
vb
<DXCategory("DragDrop")>
Public Event BeginDragDrop As BeginDragDropEventHandler

Event Data

The BeginDragDrop event's data class is BeginDragDropEventArgs. The following properties provide information specific to this event:

PropertyDescription
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
DataGets or sets the dragged data elements.
PreviewImageGets or sets a preview of dragged data elements (rows/nodes/items).

Remarks

Users can start a drag operation with a click or double click on a non-editable row/node cell or row/node indicator. In multi-select mode, users can only use indicators to drag and drop if they are not used to select rows/nodes.

Example

This example shows how to cancel a drag operation for a specific tree list node.

csharp
//You can cancel a drag-and-drop operation.
private void DragDropEvents2_BeginDragDrop(object sender, BeginDragDropEventArgs e) {
    //If the source control is a tree list,
    //the Data argument contains the collection of tree list nodes being dragged.
    List<TreeListNode> list = e.Data as List<TreeListNode>;
    if (list.Find((x) => x.GetValue(colDEPARTMENT1).ToString().Contains("Finance")) != null) {
        //Set Cancel to true to prohibit the operation.
        e.Cancel = true;
    }
}
vb
'You can cancel a drag-and-drop operation.
Private Sub dragDropEvents1_BeginDragDrop(ByVal sender As Object, ByVal e As DevExpress.Utils.DragDrop.BeginDragDropEventArgs) _
    Handles dragDropEvents1.BeginDragDrop
    'If the source control is a tree list, 
    'the Data argument contains the collection of tree list nodes being dragged. 
    Dim list As List(Of TreeListNode) = TryCast(e.Data, List(Of TreeListNode))
    If list.Find(Function(x) x.GetValue(colDEPARTMENT1).ToString().Contains("Finance")) IsNot Nothing Then
        'Set Cancel to true to prohibit the operation. 
        e.Cancel = True
    End If
End Sub

Note

Run the XtraTreeList or XtraGrid demo and click Open Solution for more examples.

See Also

DragDropEvents Class

DragDropEvents Members

DevExpress.Utils.DragDrop Namespace