[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
  Prerequisites
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Implementation Details
   [Expand]Views
   [Collapse]Grid View Data Layout
    [Expand]Columns and Card Fields
    [Expand]Bands
    [Expand]Rows and Cards
    [Expand]Nodes
     Data Cells
     Best Fit
     Compact Mode
   [Expand]Binding to Data
   [Expand]Master-Detail Data Representation
   [Expand]Data Editing and Validation
   [Expand]Grouping
   [Expand]Filtering and Searching
   [Expand]Sorting
   [Expand]Data Summaries
   [Expand]Paging and Scrolling
   [Expand]Focus, Navigation, Selection
   [Expand]Drag-and-Drop
   [Expand]Conditional Formatting
   [Expand]Appearance Customization
   [Expand]MVVM Enhancements
   [Expand]Printing and Exporting
   [Expand]End-User Interaction
   [Expand]Miscellaneous
   [Expand]Performance Improvement
   [Expand]Design-Time Features
   [Expand]Visual Elements
   [Expand]End-User Capabilities
   [Expand]Examples
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [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
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[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.
Note

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 System.Double.NaN 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?​​​​​​​