Articles in this section
Category / Section

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

1 min read

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

C#

/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),
spreadsheet.ActiveSheet["B1:B100"].AutofitColumns();
var width = spreadsheet.ActiveSheet.GetColumnWidthInPixels(2);
spreadsheet.ActiveGrid.SetColumnWidth(2,2,width); 
 
//For refreshing the view   
spreadsheet.ActiveGrid.InvalidateCell(GridRangeInfo.Col(2));
 

 

For more reference, please find the sample link below,

 

WPF

UWP

WINRT


Conclusion

I hope you enjoyed learning about how to fit columns which are inserted at runtime in Spreadsheet.

You can refer to our UWP Spreadsheet feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied