Click here to Skip to main content
15,867,297 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.2K   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

 
Questionhow to set the selected value in combobox Pin
kalpesh kawar7-Sep-20 8:04
kalpesh kawar7-Sep-20 8:04 
Questioncolumn separator like grid Pin
kalpesh kawar1-Sep-20 19:13
kalpesh kawar1-Sep-20 19:13 
Questionhow to get other columns values when using DataTable from DB Pin
babakvb9-Nov-18 21:17
babakvb9-Nov-18 21:17 
AnswerSolution: ComboBox is cleared on enter key Pin
Member 1103358213-Oct-16 22:12
Member 1103358213-Oct-16 22:12 
QuestionSelected Value Pin
Member 1110245613-Apr-15 3:21
Member 1110245613-Apr-15 3:21 
AnswerRe: Selected Value Pin
srfox23-Apr-16 0:12
professionalsrfox23-Apr-16 0:12 
QuestionGood Article Pin
demouser74310-Jul-13 9:15
demouser74310-Jul-13 9:15 
Generalthank you for posting article Pin
Aarti Meswania6-Dec-12 21:30
Aarti Meswania6-Dec-12 21:30 
QuestionAssign a value to the ValueMember property, with data loaded from a DB Pin
ronaldnin16-Jul-12 10:04
ronaldnin16-Jul-12 10:04 
QuestionCystral report calculation Pin
kwamebounty24-Jan-12 21:45
kwamebounty24-Jan-12 21:45 
QuestionAdding a new header for each Columns Pin
Member 321560111-Jan-12 0:32
Member 321560111-Jan-12 0:32 
GeneralMy vote of 5 Pin
fariborz sadighi12-Apr-11 23:32
fariborz sadighi12-Apr-11 23:32 
GeneralSelectedIndex issue [Solved] Pin
impy12-Jun-10 2:05
impy12-Jun-10 2:05 
GeneralRe: SelectedIndex issue [Solved] Pin
RedDude8-Mar-11 10:57
RedDude8-Mar-11 10:57 
QuestionHow can I show the column name Pin
nm19709-Dec-09 5:39
nm19709-Dec-09 5:39 
Questionhow to use in datagridview Pin
mkhalid0079-Jul-09 11:11
mkhalid0079-Jul-09 11:11 
Generalcolumn headers Pin
arevans19-Nov-08 6:07
arevans19-Nov-08 6:07 
GeneralRe: column headers Pin
ewansw30-Dec-08 4:43
ewansw30-Dec-08 4:43 
Generalget only one value Pin
JM ® - DE CASTRO30-Apr-08 3:22
JM ® - DE CASTRO30-Apr-08 3:22 
GeneralRTL Pin
nETbKA19-Apr-07 4:34
nETbKA19-Apr-07 4:34 
GeneralRe: RTL Pin
cavoli119-Apr-07 5:12
cavoli119-Apr-07 5:12 
You are wanting it to display right to left correct?
Try playing with the e.Graphics.DrawString line (line 245 in the verion of the code I have)in OnDrawItem(). The DrawString function has options for right to left string drawing.
GeneralRe: RTL Pin
nETbKA21-Apr-07 22:37
nETbKA21-Apr-07 22:37 
GeneralRe: RTL Pin
cavoli123-Apr-07 4:01
cavoli123-Apr-07 4:01 
GeneralIndexed items with sorted list Pin
dave.kelly28-Feb-07 21:11
professionaldave.kelly28-Feb-07 21:11 
GeneralRe: Indexed items with sorted list Pin
cavoli11-Mar-07 5:05
cavoli11-Mar-07 5:05 

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.