KB Article A2834
Visible to All Users

How to prevent end-users from hiding all grid columns

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

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.