GridControl.ForceInitialize() Method

Forces the grid control to finish its initialization. Call this method when the form is loading, before you start to change the grid's options.

Namespace: DevExpress.XtraGrid

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

public virtual void ForceInitialize()
Public Overridable Sub ForceInitialize

Remarks

After the grid control has been initialized, you can manipulate its settings safely. Call the ForceInitialize method before you:

  • group and/or sort data;
  • change summary settings;
  • expand and collapse rows;
  • create columns and change their visibility;
  • restore a layout, etc.
NOTE

The ForceInitialize method has no effect until the form's Load event occurs. For instance, nothing will happen if you add this method in the form's constructor.

The code sample below illustrates how to safely add a column to a grid.


using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;

private void XtraForm1_Load(object sender, EventArgs e)
{
    gridControl1.ForceInitialize();
    gridView1.Columns.Add();
    gridView1.Columns[gridView1.Columns.Count - 1].Caption = "Actions";
    gridView1.Columns[gridView1.Columns.Count - 1].VisibleIndex = gridView1.Columns.Count;
}
See Also