Controls - Do you extend the size of your ComboBoxes to show as many results as possible? (Windows Forms Only)
  v2.0 Posted at 24/02/2017 1:38 AM by Tiago Araujo

​​When 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.
Options Form - ComboBox with text cut off
Figure: Bad Example - You have to scroll to see all the result, and the long results are cut off
Options Form - ComboBox with Extended Height and Width
Figure: Good Example - The size of the drop down has been extended to allow user to see as much as possible
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;​

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address: