WPF Data Grid and TreeList - Automatic Best Fit

WPF Team Blog
14 May 2020

Our WPF Data Grid and TreeList v20.1 can now automatically and dynamically resize columns during scroll and edit operations.

To demonstrate this feature, we recently published the following YouTube video.

Video Script: WPF Data Grid and WPF TreeList v20.1 - Dynamic Column Resizing

Enable Automatic Best Fit

To activate this new WPF Grid and TreeList option, simply set the appropriate column's Width property to Auto.

    <dxg:GridColumn FieldName="FullName" Width="3*"/>
    <dxg:GridColumn FieldName="BirthDate" Width="2*"/>
    <dxg:GridColumn FieldName="JobTitle" Width="Auto" AllowResizing="False"/>
    <dxg:GridColumn FieldName="Phone" Width="2*"/>

Best Fit During Source Change

We also added a BestFitModeOnSourceChange option. This allows our WPF Data Grid or TreeList to calculate the optimal width for all columns when the ItemsSource changes.

<dxg:GridControl Name="grid">
		<dxg:TableView Name="view" BestFitModeOnSourceChange="VisibleRows"/>


As always, we welcome your thoughts/opinions. Please post a comment below and let us know what you think about Automatic Best Fit.

Free DevExpress Products – Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We’ll be happy to follow-up.
Andrew Tinkler
Andrew Tinkler
Keep up the good work!
15 May 2020
Peter Drier 2
Peter Drier
Auto width works great for views with regular columns.  Anyone using banded columns should beware though as that use case is not implemented well.
5 November 2021
Andrey Marten (DevExpress Support)
Andrey Marten (DevExpress Support)

Thank you for your input, Peter. The automatic best fit operation is indeed applicable to GridColumns only. The Width property in GridControlBand does not work.

If you define the Width property in columns though, this should work correctly. If you face issues with this, feel free to create a separate ticket in our Support Center
. We will be happy to assist you.

Just in case, if your point is related to the resize functionality that we are discussing in T162279
, let's continue our discussion there.

9 November 2021

Please login or register to post comments.