How to fit the columns which are inserted at runtime in WinForms Spreadsheet?
Inserting columns
User can fit the column based on its content, which are inserted at runtime in WinForms Spreadsheet (SfSpreadsheet) by calling the 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 the code example below.
//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));Sample Link: SpreadsheetDemo
Reference Link: Rows and Columns