Click here to Skip to main content
15,886,919 members
Articles / Programming Languages / C#
Article

Auto Complete Multi Column ComboBox

Rate me:
Please Sign up or sign in to vote.
3.88/5 (20 votes)
6 Oct 20051 min read 202.9K   9.4K   65   42
This is my version of an auto completing mutli column ComboBox.

Sample Image

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.

C#
//set the Data of the ColumnComboBox
myColumnComboBox.Data = myDataTable;

You can then set the column that will be displayed as the text of the combo box.

C#
//set the ViewColumn
myColumnComboBox.ViewColumn = 2;

Any columns that you don't want to display in the drop down can be hidden like this:

C#
//Set a few columns to not be shown
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#.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Indexed items with sorted list Pin
dave.kelly1-Mar-07 20:55
professionaldave.kelly1-Mar-07 20:55 
GeneralRe: Indexed items with sorted list Pin
cavoli11-Mar-07 5:14
cavoli11-Mar-07 5:14 
GeneralSet Selected Index Pin
salah_gis21-Feb-07 23:35
salah_gis21-Feb-07 23:35 
GeneralRe: Set Selected Index Pin
cavoli11-Mar-07 5:13
cavoli11-Mar-07 5:13 
QuestionMouse pointer dissapears Pin
fonk6668-Feb-07 10:01
fonk6668-Feb-07 10:01 
AnswerRe: Mouse pointer dissapears Pin
cavoli19-Feb-07 4:00
cavoli19-Feb-07 4:00 
AnswerRe: Mouse pointer dissapears Pin
sanrio55513-Mar-07 12:50
sanrio55513-Mar-07 12:50 
GeneralRe: Mouse pointer dissapears Pin
RedDude8-Mar-11 10:55
RedDude8-Mar-11 10:55 
GeneralRe: Mouse pointer dissapears Pin
Aarti Meswania6-Dec-12 20:59
Aarti Meswania6-Dec-12 20:59 
AnswerRe: Mouse pointer dissapears Pin
Aarti Meswania6-Dec-12 21:08
Aarti Meswania6-Dec-12 21:08 
AnswerRe: Mouse pointer dissapears Pin
Paganel904-Sep-15 10:32
Paganel904-Sep-15 10:32 
GeneralI can't find the control in my toolbox Pin
bigwill343410-Dec-06 9:35
bigwill343410-Dec-06 9:35 
GeneralRe: I can't find the control in my toolbox Pin
cavoliotmail.com1@h12-Dec-06 3:47
cavoliotmail.com1@h12-Dec-06 3:47 
GeneralRe: I can't find the control in my toolbox Pin
vicspainhower30-Dec-08 5:56
professionalvicspainhower30-Dec-08 5:56 
AnswerRe: Setting the SelectedIndex Pin
cavoli116-Nov-05 4:15
cavoli116-Nov-05 4:15 
GeneralRe: Setting the SelectedIndex Pin
cavoli121-Nov-05 4:28
cavoli121-Nov-05 4:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.