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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to customize the width of the GridComboboxColumn based on its HeaderText and Items?

Platform: Windows Phone |
Control: SfDataGrid |
.NET Framework: 4.5

SfDataGrid supports ColumnSizing feature that allows you to adjust the column width based on its HeaderText or data present in the cell depending upon the type of ColumnSizer that you have defined either at the SfDataGrid or column level. You cannot adjust the width of the GridComboBoxColumn based on the Items loaded from an ItemsSource of that column by using the ColumnSizer directly.

The following screenshot displays the behavior of the Auto ColumnSizer, as width of the column is calculated based on the HeaderText and cell content of the GridComboBoxColumn.

Figure 1: Column width set based on Auto ColumnSizer

In the SfDataGrid, you can adjust the width of GridComboBoxColumn based on the items loaded from an ItemsSource of that column. To achieve this, customize the column width based on the loaded items in GridComboBoxColumn by deriving a new class from the GridColumnSizer class and overriding its CalculateCellWidth () virtual method. The following code example illustrates how to derive a new class from GridColumnSizer and override its CalculateCellWidth () virtual method.


The above CalculateCellWidth () method is invoked to calculate the width of each column in the SfDataGrid. You can customize the column width based on the items in GridComboBoxColumn as follows.


You can get each item of GridComboBoxColumn by accessing an ItemsSource of the corresponding column and comparing the length of each item to the others in the collection and storing the item having the maximum length. By using the MeasureText () method, you can get the corresponding Height and Width of the maximum combo item text.

Assign the instance of the above CustomColumnSizer class to SfDataGrid’s GridColumnSizer property as illustrated in the following code example.


The above customized width is applied to GridComboBoxColumn as displayed in the following screenshot.

Figure 2: Customized column width applied to Country column based on its loaded items

Sample Links





You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon 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.Close Icon

Live Chat Icon For mobile