How to access Columns for DevExpress.XtraGrid.GridControl in C#

Kevin Busch picture Kevin Busch · Sep 24, 2012 · Viewed 17.1k times · Source

I try to get the ColumnNames and the current Vieworder of my GridControl. The docu won't help me an the ".Net Reflector"-Tool also won't give me advice.

The tip from an other stackoverflowpost ( How to hide column of devexpress XtraGrid ) also won't help me, because, i can't access View.Columns

Answer

pakeha_by picture pakeha_by · Sep 24, 2012

I suggest you are trying to use property gridControl.MainView to access a view. This property is of type BaseView (base class for all views) so in order to access columns/order information you should cast it to GridView (or whatever type you are using):

var firstColumnName = ((GridView)gridControl.MainView).Columns[0].FieldName;