[DevExpress Support Team: CLONED FROM Q139901: Apply Best Fit for all columns]
Where should I put the BestFit method?
GridView - Where in code the BestFitColumns method can be invoked
Answers approved by DevExpress Support
You can invoke this method in any place of the target container.
For instance, if you need to apply best fit to columns before the grid is shown, you can handle the Load event in the following manner:
C#private void Load(object sender, EventArgs e)
{
gridControl1.ForceInitialize();
gridView1.BestFitColumns();
}
Since GridControl isn't completely initialized before it is visible for the first time, it is better to invoke the GridControl.ForceInitialize method to force this process in order to ensure the proper work of the BestFitColumns method.
I've created a sample project to demonstrate the main idea of how this works. Please test the project and let me know your results.