Category / Section
How to apply column sizer based on device orientation ?
1 min read
SfDataGrid allows you to customize the SfDataGrid.ColumnSizer based on the requirement. You can apply different ColumnSizer based on orientation of the device and the SfDataGrid will rearrange the view accordingly.
Refer the below code example in which the SfDataGrid.ColumnSizer is customized based on orientation by checking the orientation of the device in the ViewLayoutSubViews override method of the ViewController which will be fired when the view changes.
public override void ViewDidLayoutSubviews() { base.ViewDidLayoutSubviews(); if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeLeft || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeRight) this.datagrid.ColumnSizer = ColumnSizer.Star; else this.datagrid.ColumnSizer = ColumnSizer.Auto; datagrid.Frame = new CoreGraphics.CGRect(0, 0, View.Frame.Width, View.Frame.Height ); }
The following screenshots shows the final outcome when the above code is executed.
Sample Link: