Introduction
I have seen a few other multi column combo boxes and auto complete combo boxes so I decided to submit this code that does both.
Background
A while ago I needed to move a project from MS Access to C#. In Access it was using a lot of their nifty columned combo boxes and our customers would struggle mightily if there were any changes to this functionality. Thus the ColumnComboBox
was born.
Using the code
This class can be used like any other ComboBox except the Items
should be set using the Data
property. This is a DataTable
from which the ColumnComboBox
gets all the data for filling the drop down box. Simply fill a DataTable
as desired and then set the Data
property with it.
myColumnComboBox.Data = myDataTable;
You can then set the column that will be displayed as the text of the combo box.
myColumnComboBox.ViewColumn = 2;
Any columns that you don't want to display in the drop down can be hidden like this:
myColumnComboBox.Columns[1].Display = false;
myColumnComboBox.Columns[3].Display = false;
There are a few other properties to play with such as being able to turn auto complete off (myColumnComboBox.Suggest = false;
) or an indexer for getting values from columns at the current rows.
Points of Interest
The code uses a few helper classes that are included either below the ColumnComboBox
class or in another included file (StringList
). The source for the ColumnComboBox
is commented if you want to poke around yourself. I for one will be happier when/if they get templates into C#.