Description:
I want to prevent end-users from moving the last grid column to the Customization form. In other words, I do not want the grid to be blank (not have any columns).
Answer:
An end-user can hide grid columns only by dragging them out of the column header panel. When column headers are being dragged, the DragObjectOver event is fired and allows you to disable column dropping at the mouse's current position. Thus, you should handle the DragObjectOver event of your GridView. Here is the necessary code.
C#using DevExpress.XtraGrid.Columns;
private void gridView1_DragObjectOver(object sender, DevExpress.XtraGrid.Views.Base.DragObjectOverEventArgs e) {
GridColumn column = e.DragObject as GridColumn;
if(column != null &&
column.View.VisibleColumns.Count == 1 && column.View.VisibleColumns[0] == column
&& e.DropInfo.Index < 0) {
e.DropInfo.Valid = false;
}
}
See Also:
How to catch the moment when a column's position is changed