We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to autosize column widths in SfDataGrid?

Thread ID:

Created:

Updated:

Platform:

Replies:

118961 Apr 28,2015 12:11 PM Apr 30,2015 03:26 AM Xamarin.Android 3
loading
Tags: General
Michel
Asked On April 28, 2015 12:11 PM


I am trying to autosize column widths in the new SfDataGrid for Xamarin.Android (Preview), but I can't find the right option. Now my columns are fixed width and behave differently on small & large screen resolutions.

Is column autosizing not implemented yet or is there a workaround?

Regards, Michel.

Harikrishnan N [Syncfusion]
Replied On April 29, 2015 08:05 AM

Hi Michel,

Sorry for the inconvenience caused

At present there is no support for “Column AutoSizing”. However you can set the default column width by using the SfDataGrid.DefaultColumnWidth property or you can set the individual column’s width by handling the SfDataGrid.AutoGeneratingColumn event and by setting the Column.Width property of each column to meet your requirement. Please refer the below code snippet.

//Setting the Column width of all the columns

sfGrid.DefaultColumnWidth = 180;

sfGrid.AutoGeneratingColumn += GridAutoGenerateColumns;


void GridAutoGenerateColumns (object sender, AutoGeneratingColumnArgs e)

{

if (e.Column.MappingName == "SupplierID") {

e.Column.Width = 150;

}

/// more code for other columns
}


We have this Feature in our wish list and it will be implement in our upcoming release.

Please let us know if you have any further queries.

Regards,
Harikrishnan.


Michel
Replied On April 29, 2015 08:18 AM

Thanks for your reply Harikrishnan.

I have come up with the following solution for now:

During the column definition I first get the ScreenWidth and ScreenHeight by calling:
    App.ScreenWidth = (int)Resources.DisplayMetrics.WidthPixels; // real pixels
    App.ScreenHeight = (int)Resources.DisplayMetrics.HeightPixels; // real pixels

Then I assign the Width of each column to a percentage of that ScreenWidth.
If the sum adds up to 100% I can be sure that it fits on the screen.

Looking forward to the next release. Is there a public wishlist available?

Regards, Michel.


Harikrishnan N [Syncfusion]
Replied On April 30, 2015 03:26 AM

Hi Michel,

Sorry, There is no public wishlist available.

Please let us know if you have any further queries.

Regards,
Harikrishnan


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;