GridView.DragObjectOver Event

Enables you to control whether the dragged column header or band header can be dropped at the current position.

Namespace: DevExpress.XtraGrid.Views.Grid

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

[DXCategory("DragDrop")]
public event DragObjectOverEventHandler DragObjectOver
<DXCategory("DragDrop")>
Public Event DragObjectOver As DragObjectOverEventHandler

Event Data

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

Property Description
DragObject Gets the column or band whose header is being dragged.
DropInfo Gets an object containing information about the dragged header's current position.

Remarks

The DragObjectOver event fires repeatedly when dragging a column or band header. This event lets you prevent dropping at the current position.

Use the event's DragObjectOverEventArgs.DragObject and DragObjectOverEventArgs.DropInfo parameters to identify the element being dragged and to obtain its current position. To prevent dropping, set the Valid property of the DragObjectOverEventArgs.DropInfo object to false. This changes the mouse cursor to the MouseCursorNo image and the View will ignore a subsequent drop of the dragged object.

Note that the GridView.DragObjectDrop event occurs regardless of the operation's result. Its DragObjectDropEventArgs.Canceled parameter will be set to false if the drag and drop operation was canceled.

For general information on handling column and band header dragging, see the GridView.DragObjectStart topic.

Examples

The example shows how to prevent moving the "ContactName" column to the Customization Form.

To control drag-and-drop of grid columns, we handle the GridView.DragObjectOver event. The DragObjectOverEventArgs.DropInfo event's parameter contains information on the current position where drag-and-drop will occur if the end-user drops the drag object. The Index property of the DragObjectOverEventArgs.DropInfo would be -1 when dragging over the Customization Form.

using DevExpress.XtraGrid.Views.Base;

private void bandedGridView1_DragObjectOver(object sender, DragObjectOverEventArgs e) {
    GridColumn column = e.DragObject as GridColumn;
    if (column != null) {
        e.DropInfo.Valid = !(e.DropInfo.Index == -1 && column.FieldName == "ContactName");
    }
}
See Also