Working with a ComboBox
For this lesson, download the sample project: ComboBox
The ComboBox is a very useful control.
Whenever a user has to input data into a form the risk of errors is great. Any data that is keyed by the user can be incorrectly recorded, leading to erors in data files and calculations.
Anything that can be done to minimize the risk of errors will make the application stronger and more efficient.
The ComboBox and the ListBox work in similar ways. They both offer the user a list of choices from which to choose without having to key the data.
The difference between the two is that the ListBox offers a fixed list of choices without the option to change anything.
The ComboBox on the other hand gives some flexibility in that the user is allowed to add and delete items from the list offered.
In our example, you are allowed to add an item to the list if it doesn't already exist (note that it is case sensitive). You can also delete items from the list as you wish.
Obviously, adding or removing items from te list only makes sense when the ComboBox is in a form used in a processing loop.
When new list items may appear between invoices, for example, you would give the user the option of adding the new items as they come up.
Another point to note is that the combo list of items is loaded at run-time in the Form_Load event. This is useful because it gives you the option to chnge the initial list fairly easily.