Column ResizeToFit ComboBox Question

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

2 Replies

HA haneefm Syncfusion Team April 12, 2007 06:09 PM UTC

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


KD Kyle DeVoe April 12, 2007 06:50 PM UTC

Haneef,

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

Kyle

Loader.
Up arrow icon