Skip to main content

How to: Control Drag-and-drop of Column Headers

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");
    }
}