Controls - Do you extend the size of your ComboBoxes to show as many results as possible? (Windows Forms Only)
Last updated by Brady Stroud [SSW] 7 months ago.See historyWhen designing your form, it's a good idea to help your user whenever it's possible. So it's a good idea to extend your ComboBoxes to show as many results as possible to save your user from scrolling. Also, you should extend the width of the dropdown in order to show the longest items.
However, you should not extend your ComboBox without limit, normally the maximum number of items should be under 10 and the maximum width of the drop-down should be smaller than your hosting form.
Changing the maximum items is easy, just include the following code in your form:
cbxOUList.MaxDropDownItems = cbxOUList.Items.Count;
// Changing the drop down size is a bit of tricky
Graphics g = Graphics.FromHwnd(this.Handle);
SizeF stringSize = new SizeF();
stringSize = g.MeasureString(longString, cbx.Font, 600);
int adjustedSize = cbx.DropDownWidth;
if (adjustedSize < (int) stringSize.Width) {
adjustedSize = (int) stringSize.Width;
}
cbx.DropDownWidth = adjustedSize;