Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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