How to fit columns which are inserted at runtime in UWP Spreadsheet?
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,
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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!