This is a migrated thread and some comments may be shown as answers.

Resize popup for ComboBoxColumn to fit items

1 Answer 117 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 05 Apr 2012, 01:09 AM

Hi,

Can I resize the popup in a ComboBoxColumn to fit the items in the list? I know I can use the:

Popup.MinimumSize
Popup.Size

 But is there a way to autosize to bestfit the contents of the list?

Kind Regards
Justin


1 Answer, 1 is accepted

Sort by
0
Accepted
Ivan Petrov
Telerik team
answered on 09 Apr 2012, 12:25 PM
Hi Justin,

Thank you for writing.

You can achieve this by setting the DropDownWidth of the editor's element. You have to first measure the width you will need and then assign it to the property. Here is how to do this inside the CellEditorInitialized event:
private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
  RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
 
  if (editor == null)
  {
    return;
  }
 
  RadDropDownListElement element = editor.EditorElement as RadDropDownListEditorElement;
 
  int scrolBarWidth = 0;
 
  if (element.DefaultItemsCountInDropDown < element.Items.Count)
  {
    scrolBarWidth = 35;
  }
 
  foreach (RadListDataItem item in element.Items)
  {
    string text = item.Text;
    Size size = TextRenderer.MeasureText(text, element.Font);
 
    if (element.DropDownWidth < size.Width)
    {
      element.DropDownWidth = size.Width + scrolBarWidth;
    }
  }
}

I hope this will be useful for you. Should you have further questions, I would be glad to help.

Kind regards,
Ivan Petrov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Justin
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Share this question
or