ComboBox display value width

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
Is there a way to have the view/display width different from the width as it
sits on the form?

Thanks
Brian
 
You can set the width of the ComboBox at runtime like so where XXX is
an integer representing the number of pixels:

ComboBox.Width = XXX;
 
OK, its not the combo width, the width of the dropdown text value field when
someone clicks the combobox. so the combo is width 50 but there are values
that are 100 long, so when the user clicks the combo the drop down part is
wider than the combo control.

Brian
 
Change Dropdown Width
int maxWidth = 100;
using (Graphics g = ComboBox.CreateGraphics())
{
foreach (object o in ComboBox.Items)
{
int w = Convert.ToInt32(g.MeasureString(o.ToString(), ComboBox.Font).Width);
if (w > maxWidth) maxWidth = w;
}
}
ComboBox.DropDownWidth = maxWidth;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top