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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Refresh Column Width while adding records at run time

Platform: UWP |
Control: SfDataGrid

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.


private void AddRecords_Click(object sender, RoutedEventArgs e)
    var viewmodel = (this.DataContext as ViewModel);


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


Figure 1: Column Width Updated in grid

Sample Links






2X faster development

The ultimate UWP UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon 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.Close Icon

Live Chat Icon For mobile