Not logged in - Login

Set DevExpress Grid Columns to be Read Only

Use the following example to set a DevExpress grid to be editable or not.

// set to be the grid control
DevExpress.XtraGrid.GridControl grd = xxx; 

// get the visible GridView object on the grid
DevExpress.XtraGrid.Views.Grid.GridView gvw = grd.MainView as DevExpress.XtraGrid.Views.Grid.GridView; 

// flag to allow edits, or not
bool bAllowEdits = false;

// set row edits
gvw.OptionsBehavior.Editable = bAllowEdits ;
grd.EmbeddedNavigator.Buttons.Edit.Enabled = bAllowEdits ;

// set row deletes
grd.EmbeddedNavigator.Buttons.Remove.Enabled = bAllowEdits ;

// set the Insert row visibility
if (bAllowEdits)
   gvw.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Top;
   gvw.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.None;

The above can be set in code, or can be set during design time.