GridControl.CalcBestSize(Size, Boolean) Method
Calculates the grid size required to fit its content or to display the maximum number of rows and columns. The size cannot exceed the specified maximum size.
Namespace: DevExpress.XtraGrid
Assembly: DevExpress.XtraGrid.v24.1.dll
NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation
Declaration
Parameters
Name | Type | Description |
---|---|---|
maxSize | Size | The maximum allowed size. |
Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
checkScrollInfo | Boolean | False |
|
Returns
Type | Description |
---|---|
Size | The optimal grid size required to fit its content. |
Remarks
You can use the CalcBestSize
method to resize the grid to its optimal size. In this case, you must call this method twice: to calculate the grid size and to include scrollbars in the calculation (they may appear/disappear after the first resize).
gridControl1.Size = gridControl1.CalcBestSize(new System.Drawing.Size(1600, 1200), false);
gridView1.LayoutChanged();
gridControl1.Size = gridControl1.CalcBestSize(new System.Drawing.Size(1600, 1200), true);
gridView1.LayoutChanged();
You can also call the GridView.BestFitColumns method to resize grid columns to the optimal width.
Usage Notes
- The
CalcBestSize
method supports only GridView and its descendants. - The
CalcBestSize
method ignores group row content and the Group Panel width. - In master-detail mode, the
CalcBestSize
method calculates the optimal width only for the master view.