Back to Devexpress

SpreadsheetControl.BeforeDropRange Event

windowsforms-devexpress-dot-xtraspreadsheet-dot-spreadsheetcontrol-667d71ac.md

latest3.7 KB
Original Source

SpreadsheetControl.BeforeDropRange Event

Occurs when a user is about to drop the selected cell range in a new location.

Namespace : DevExpress.XtraSpreadsheet

Assembly : DevExpress.XtraSpreadsheet.v25.2.dll

NuGet Package : DevExpress.Win.Spreadsheet

Declaration

csharp
public event BeforeDropRangeEventHandler BeforeDropRange
vb
Public Event BeforeDropRange As BeforeDropRangeEventHandler

Event Data

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

PropertyDescription
CancelGets or sets whether to cancel the drag-and-drop operation for the selected cell range.
OperationTypeGets the drag-and-drop operation type.
SourceRangeReturns a cell range that a user is about to move or copy to a new location.
TargetRangeReturns a cell range into which a user is about to paste data.

Remarks

The BeforeDropRange event fires in the following cases:

  • When a user drags a cell range in a new location in a worksheet (OperationType is MoveCells).

  • When a user drags a cell range in a new location with the Ctrl key pressed. In this case, source cells are copied to the destination range (OperationType is CopyCells).

Set the event’s Cancel parameter to true to cancel the operation. The following example shows how to prevent the move operation for a data table.

csharp
Table table = worksheet.Tables[0];
// ...

spreadsheetControl1.BeforeDropRange += (s, e) => {
    if (e.OperationType == DragDropOperationType.MoveCells && table.Range.IsIntersecting(e.SourceRange))
        e.Cancel = true;
};
vb
Dim table As Table = worksheet.Tables(0)
' ...

AddHandler SpreadsheetControl1.BeforeDropRange,
    Sub(s, e)
        If e.OperationType = DragDropOperationType.MoveCells AndAlso table.Range.IsIntersecting(e.SourceRange) Then
            e.Cancel = True
        End If
    End Sub

The AfterDropRange event is raised when the drag-and-drop operation is completed.

See Also

BeforeDragRange

AfterDropRange

SpreadsheetControl Class

SpreadsheetControl Members

DevExpress.XtraSpreadsheet Namespace