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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridComboBoxColumn resize to options.

Thread ID:





118993 May 1,2015 08:25 PM UTC May 5,2015 06:40 AM UTC WinRT 3
Tags: SfDataGrid
Asked On May 1, 2015 08:25 PM UTC


I have a GridComboBoxColumn column with ColumnSizer set to Auto, it resizes based on both the header & selected text. I am wondering if there a way column width can be resized to longest option or header text whichever is longer?

For example: 
Lets say, header text is "Employee Name" and below are the options:
Option 1
Option 2
Option Last With Lengthy text

with ColumnSizer  set to Auto,
a.  when there is no option selected, it sizes to fit header("Employee Name")
b.  when an option is preselected, it sizes to whichever is longer(header or selected option text).
How can I make the column width to size to longest text either in header or drop down options. So in this case longest text would to "Option Last With Lengthy text"

Second question is related to the width of the combobox options selection window. Currently selection window resizes to the displayed options. Lets say options are: 1, 2, 3, 4, 5, 6, 7 and "A long Text", when expanding drop down by default shows 1-6 options and when you scroll to last option it increases the selection window width to show the last option full text. Is it possible to make that selection window size fixed and size to longest option? 

Gobikrishnan Murugesan [Syncfusion]
Replied On May 4, 2015 05:39 PM UTC

Hi Vasanth,

Thank you for usingSyncfusion Products.

We have analyzed your query and you can achieve your requirement by customizing default GridColumnSizer.For customizing, you need to create customized GridColumnSizer by deriving it from GridColumnSizer class. In the customized GridColumnSizer, you need to override the CalculateCellWidth method.

Please refer the below code snippet to create customize GridColumnSizer and override the CalculateCellWidth method.

Code Snippet:








///Calculate Width for Column When Column Sizer is SizeToCells


///<param name="column">GridColumn</param>

///<returns>column width</returns>

protectedoverridedoubleCalculateCellWidth(GridColumncolumn,boolsetWidth =true)


if(column.HeaderText =="City")


varcolIndex =this.DataGrid.Columns.IndexOf(column);

intscrollColumnIndex =this.DataGrid.ResolveToScrollColumnIndex(colIndex);

doublecolWidth = column.Width;

varsource = (columnasGridComboBoxColumn).ItemsSource;

stringprevtext =string.Empty;

stringlengthtext =string.Empty;

varclientSize =newSize(colWidth, DataGrid.RowHeight);



stringstr = (string)r;

if(prevtext.Length < str.Length)

lengthtext = str;

prevtext = str;


doublewidth = Getwidth(lengthtext, clientSize);




returnbase.CalculateCellWidth(column, setWidth);




TextBlockTextBlock =newTextBlock()


FontFamily = FontFamily,

Margin = Margin,

FontSize = FontSize


TextBlock.Text = DisplayText;

varparentBorder =newBorder{ Child = TextBlock };

TextBlock.MaxHeight = size.Height;

TextBlock.MaxWidth =double.MaxValue;

parentBorder.Measure(newSize(TextBlock.MaxWidth, TextBlock.MaxHeight));

parentBorder.Child =null;




After creating customized GridColumnSizer, you need to add the customized GridColumnSizer as shown in below code snippet,






//add customized GridColumnsSizer to dataGrid

datagrid.GridColumnSizer =newGridColumnAutoSizerExt(datagrid);



We have prepared a sample for your requirement also and please refer the sample from below location.

Sample location:


Please let us know if you have any queries.


Gobikrishnan M

Replied On May 4, 2015 08:13 PM UTC

your solution works great, thanks!

Saranya CJ [Syncfusion]
Replied On May 5, 2015 06:40 AM UTC

Hi Vasanth,

Thank you for your update. Please let us know if you require further assistance on this.



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.

Please sign in to access our forum

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

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