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.
Syncfusion Feedback

Column ResizeToFit ComboBox Question

Thread ID:

Created:

Updated:

Platform:

Replies:

59424 Apr 12,2007 09:28 AM Apr 12,2007 02:50 PM Windows Forms 2
loading
Tags: GridControl
Kyle DeVoe
Asked On April 12, 2007 09:28 AM

I have a question about using the column ResizeToFit() function. If if have a combobox in my column, the column will resize to the longest string in my combobox choicelist, even if that string isn't the selected item. How do I get the grid to ignore the choice list and only resize the column based on the display text in the combobox?

thanks,
Kyle

haneefm [Syncfusion]
Replied On April 12, 2007 02:09 PM

Hi Kyle,

This can be acheived by deriving the GridComboBoxCellModel class and overriding OnQueryPrefferedClientSize Method to change the default resizing behavior of the combo box cell in a grid. Here is a code snippet to show this.

public class MyComboBoxCellModel : GridComboBoxCellModel
{
public MyComboBoxCellModel(GridModel grid): base(grid){}

protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)
{
Size size = g.MeasureString(style.FormattedText,style.GdipFont).ToSize();
return size + this.ButtonBarSize;
}
public override GridCellRendererBase CreateRenderer(GridControlBase control)
{
return new MyComboBoxCellRenderer(control, this);
}
}

Here is a sample.
ResizeToFitComboBox.zip

Best Regards,
Haneef

Kyle DeVoe
Replied On April 12, 2007 02:50 PM

Haneef,

thank you for the example. This seems to be working well. Thanks for the quick reply.

Kyle

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.

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

;