We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to refresh Column Width while adding records at run time?

SfDataGrid.ColumnSizer property (type of GridLengthUnitType) provides different in-built options to specify the column width based on the data present in the cell and available width. GridLengthUnitType.SizeToCells, GridLengthUnitType.Auto and GridLengthUnitType.AutoWithLastColumnFill options is used to set the width of the column with respect to the cell content.

The width of the columns are calculated while loading SfDataGrid and when you are adding the record at runtime, the width of the columns is not refreshed based on ColumnSizer. You can refresh ColumnSizer at runtime by calling SfDataGrid.GridColumnSizer.Refresh() method. When you are using GridLengthUnitType.SizeToCells, GridLengthUnitType.Auto or GridLengthUnitType.AutoWithLastColumnFill options, you can reset the previously calculated widths by calling SfDataGrid.GridColumnSizer.ResetAutoCalculationforAllColumns() method before calling Refresh method. You can reset the width for a particular column by using SfDataGrid.GridColumnSizer.ResetAutoCalculation() method. So that the width calculation is done only for the particular column that provides better performance.

 

In the following code example, ColumnSizer is refreshed at runtime after adding records.

C#

 

The following screenshot displays the column widths that are set based on its cell content.

C:\Users\Giftline\Desktop\a.png

Figure 1: Column Width Updated in grid

Sample Links

WPF

WRT

SilverLight

UWP

 

Article ID: Published Date: Last Revised Date: Platform: Control:
3639 01/30/2015 02/05/2016 WinRT SfDataGrid
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.