Category / Section
How to customize ColumnSizer based on orientation in SfDataGrid?
2 mins read
The SfDataGrid allows you to customize the SfDataGrid.ColumnSizer based on orientation by using the SfDataGrid.SizeChanged event. It automatically refreshes the view based on the ColumnSizer when orientation is changed.
public void dataGrid_SizeChanged(object sender, EventArgs e) { //Orientation is Landscape. Hence setting ColumnSizer as "Star". if (dataGrid.Width > dataGrid.Height) dataGrid.ColumnSizer = ColumnSizer.Star; //Orientation is Portrait. Hence setting ColumnSizer as "Auto". else dataGrid.ColumnSizer = ColumnSizer.Auto; }
Screenshot:
Orientation: Portrait Orientation: Landscape
Sample Link:
How to customize ColumnSizer based on orientation in SfDataGrid