Column width in percentage

How can I set columns of SfDataGrid width in percentage in Xamarin.Forms project?
For example I have two columns, and I want first one to be 30% and second one 70%.

1 Reply

VP Vimal Prabhu Manohkaran Syncfusion Team October 18, 2017 07:03 AM UTC

Hi Jelena,

Thanks for using Syncfusion products. Regarding your query of setting column widths in percentage, currently it is not possible to set width in percentage directly to the GridColumns. However you can assign width to individual columns based on the overall size the SfDataGrid is layout to in the application. Please hook the SfDataGrid.GridLoaded event and use the below codes in the GridLoaded event handler to achieve your requirement.

 
private void DataGrid_GridLoaded(object sender, GridLoadedEventArgs e) 
{ 
    var percentage = dataGrid.Width / 100; 
    dataGrid.Columns[0].Width = percentage *30; 
    dataGrid.Columns[1].Width = percentage * 70; 
} 

Please refer the below sample where we have set width such that the first column takes 30% of the screen and the second column takes 70% of the DataGrid.
Sample Link : http://www.syncfusion.com/downloads/support/forum/133250/ze/Forms1244071606

Regards,
Vimal Prabhu
 
 


Loader.
Up arrow icon