[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Implementation Details
   [Collapse]Grid View Data Layout
    [Expand]Columns and Card Fields
    [Expand]Rows and Cards
     Data Cells
     Best Fit
     Column Chooser
     Compact Mode
   [Expand]Binding to Data
   [Expand]Master-Detail Data Representation
   [Expand]Data Editing and Validation
   [Expand]Filtering and Searching
   [Expand]Data Summaries
   [Expand]Paging and Scrolling
   [Expand]Focus, Navigation, Selection
   [Expand]Conditional Formatting
   [Expand]Appearance Customization
   [Expand]MVVM Enhancements
   [Expand]Printing and Exporting
   [Expand]Performance Improvement
   [Expand]Design-Time Features
   [Expand]Visual Elements
   [Expand]End-User Capabilities
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Best Fit

The GridControl can calculate and apply the optimal width required for a column or band to display all its contents.

You can apply the Best Fit feature to:

  • An individual column.
  • An individual band.
  • All view's columns and bands.

You cannot apply the Best Fit feature to a column if:

Expanded Applying Best Fit

At Runtime

End-users can do the following to apply Best Fit to a column (or band):

  • Double click the column (or band) header's right border:

  • Right-click the column (or band) header and select the Best Fit item in the invoked context menu:

In Code

The following methods allow you to apply the Best Fit feature:

Method Description
TableView.BestFitColumn (TreeListView.BestFitColumn) Resizes the specified column to the optimal width required to display all its contents.
TableView.BestFitColumns (TreeListView.BestFitColumns) Resizes all columns displayed within the current View to the optimal width required to display their contents.

Use these methods after the GridControl has been loaded.

Expanded Allowing Best Fit

You and your end-users can apply Best Fit to any column by default. You can set the following properties to false to forbid end-users to apply Best Fit for a required column or all columns:

Property Description
BaseColumn.AllowBestFit Gets or sets whether it is allowed to calculate an optimal width and apply it to the column.
TableView.AllowBestFit (TreeListView.AllowBestFit) Gets or sets whether it is allowed to calculate the optimal widths and apply them to all columns in a View.

Expanded Best Fit Options

The GridControl has a set of members that allow you to control the Best Fit feature manually:

Property Description
TableView.BestFitArea, TreeListView.BestFitArea, ColumnBase.BestFitArea Allows specifying interface elements (column header, cells, etc.) which should be taken into account when adjusting column widths.
TableView.BestFitMode, TreeListView.BestFitMode, ColumnBase.BestFitMode If cell values are taken into account when calculating a column's optimal width, you can specify the way this width is calculated. A column's width is calculated based on all cells' text within this column by default.
TableView.BestFitMaxRowCount, TreeListView.BestFitMaxRowCount, ColumnBase.BestFitMaxRowCount You can increase the application's performance by limiting the number of records taken into account when calculating the optimal width. This property is set to -1 by default to indicate that all cells are processed. If the property is set to a positive value, a View processes the specified number of cells starting from the top visible cell.
BaseColumn.BestFitWidth Specifies a column's width when the Best Fit feature is applied to this column.
TableView.CalcColumnBestFitWidth (TreeListView.CalcColumnBestFitWidth) Returns the column's optimal width required to display all its contents.
TableView.CustomBestFit (TreeListView.CustomBestFit) Allows you to manually calculate the optimal width for a column(s).

Expanded See Also

Is this topic helpful?​​​​​​​