Skip to main content

DataGridView.DragRow Event

Occurs when users touch and hold a data row to drag it.

Namespace: DevExpress.XamarinForms.DataGrid

Assembly: DevExpress.XamarinForms.Grid.dll

NuGet Package: DevExpress.XamarinForms.Grid

Declaration

public event EventHandler<DragRowEventArgs> DragRow

Event Data

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

Property Description
Allow Gets or sets whether to allow or prohibit an operation with the row. Inherited from RowAllowEventArgs.
DragItem Gets a data source item that corresponds to the dragged row.
RowHandle Gets the grid’s row handle. Inherited from RowEventArgs.

Remarks

The DragRow event allows you to manage the drag action.

You can use this event to prevent drag of the specified row:

  1. Subscribe to the DragRow event.

    <dxg:DataGridView AllowDragDropRows="True" 
                      DragRow="grid_DragRow"/>
    
  2. In the event handler, specify a row(s) that cannot be dragged. Use the RowHandle or DragItem property to identify the row by its handle or data source item. Set the Allow property to false to prevent drag-and-drop operations.

    The following example checks whether a user drags the first task. If the task is not completed, the user cannot drag it.

    using DevExpress.XamarinForms.DataGrid;
    
    // ...
    private void grid_DragRow(object sender, DragRowEventArgs e) {
        var currentItem = (EmployeeTask)e.DragItem;
        if (!currentItem.Completed && e.RowHandle == 0) {
                DisplayAlert("Alert", "The task '" + currentItem.Name 
                + "' is in progress. You cannot move it from the first position.", "OK");
                e.Allow = false;
            }
    }
    
See Also