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

How to fit the columns which are inserted at runtime in Spreadsheet?

Platform: WPF |
Control: SfSpreadsheet

User can fit the column based on its content, which are inserted at runtime in SfSpreadsheet by calling AutofitColumns method for the inserted range and setting the column width using SetColumnWidth function of SpreadsheetGrid and then refresh the UI using InvalidateCell method like below code example


/For inserting columns,
spreadsheet.ActiveSheet.InsertColumn( 2, 1, ExcelInsertOptions.FormatAsAfter);
spreadsheet.ActiveGrid.Model.InsertColumns(2, 1);
//For setting cell value,
var range = spreadsheet.ActiveSheet.Range[2, 2];
spreadsheet.ActiveGrid.SetCellValue(range, "This is a sample using Autofit");
//For Auto fit that particular column(2),
var width = spreadsheet.ActiveSheet.GetColumnWidthInPixels(2);
//For refreshing the view   


For more reference, please find the sample link below,





2X faster development

The ultimate WPF 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