Tag Archives: ComboBox

Sort partly numeric items in a ComboBox or ListBox in C#

The example Use a custom sort order for ListBox or ComboBox items in C# shows how to sort numeric values. This example uses the same basic approach: make an array of values, sort them as you want them displayed, and … Continue reading

Posted in algorithms, controls | Tagged , , , , , , , , , , , | 1 Comment

Use a custom sort order for ListBox or ComboBox items in C#

If you set a ComboBox and ListBox control’s Sorted property to true, the control sorts the items it contains. Unfortunately it sorts the items alphabetically. That means if the items are strings that begin with Roman numerals, they may be … Continue reading

Posted in algorithms, controls, user interface | Tagged , , , , , , , , , , , , , , , | 2 Comments

Sort ListBox or ComboBox items in numeric order in C#

If you set a ListBox control’s Sorted property to true, the control sorts its contents. Unfortunately it can only sort its contents in alphabetic order. If the items are numeric, that may not be what you want. This example sorts … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , | Leave a comment

Make a ComboBox display images with text in C#

The example Make a ComboBox display colors or images in C# shows how to make an owner-drawn ComboBox that displays either a series of color samples or a list of images. This example shows how to make a ComboBox that … Continue reading

Posted in controls, extension methods, graphics | Tagged , , , , , , , , , , , , | 11 Comments

Make a ComboBox display colors or images in C#

There are two kinds of owner-drawn ComboBox controls. In the first kind, every item has the same size. In the second kind of ComboBox, each item can have a different size. Same Sized Items To make all items have the … Continue reading

Posted in controls, extension methods, graphics | Tagged , , , , , , , , , , , , | 6 Comments

Let the user pick database search criteria in C#

The top part of this program holds three columns of controls. The left column contains combo boxes holding the names of the fields in a database table. The middle column holds operators such as =, <, and >=. The right … Continue reading

Posted in database, user interface | Tagged , , , , , , , , , , , | 1 Comment

Add ComboBox choices at runtime in C#

This example lets you add ComboBox choices when the user selects them at runtime. To keep track of the choices for future use, it saves them in the Registry. The example Easily save and restore a form’s settings in the … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , , , | Leave a comment

Initialize a ComboBox from an enumeration in C#

Often it’s useful to initialize a ComboBox from an enumeration so the user can pick one of the enumeration’s values. You could type the value into the ComboBox at design time, but then if the enumeration changes, you’ll have to … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , , | Leave a comment

Select ComboBox or ListBox values that contain target text in C#

The List timezones in C# example fills a ComboBox with a list of timezones. I would like to select an initial value based on the text in the items, but I don’t want to have to select the exact text, … Continue reading

Posted in controls, interfaces | Tagged , , , , , , , , , , , , , , | 1 Comment

Override ToString to allow controls such as ListBox to display objects in C#

All classes inherit the ToString method from the Object ancestor class. Controls such as ComboBox and ListBox use the ToString methods of the objects they contain to decide what to display. By default, ToString returns a class’s name, which is … Continue reading

Posted in classes, OOP, strings, syntax | Tagged , , , , , , , , , , , , , | 4 Comments