Click here to Skip to main content
12,445,907 members (68,602 online)
Click here to Skip to main content
Add your own
alternative version

Stats

598.3K views
38.8K downloads
176 bookmarked
Posted

Multi Column ComboBox

, 17 Nov 2002
Rate this:
Please Sign up or sign in to vote.
Displaying Multiple Columns in a Dropdown Combobox

Introduction

This is a simple example of how to display table values (i.e. multiple columns) in a combo box. For the dropdown window, a form with a ListView docked to fill can be used. The MultiColumnCombobox class is inherited from the System.Windows.Forms.Combobox class.

protected override void OnDropDown(System.EventArgs e){
    Form parent = this.FindForm();
    if(this.dataTable != null || this.dataRows!= null){
        MultiColumnComboPopup popup = new 
                            MultiColumnComboPopup(this.dataTable,
                            ref this.selectedRow,columnsToDisplay);
        popup.AfterRowSelectEvent+=
                            new AfterRowSelectEventHandler
                            (MultiColumnComboBox_AfterSelectEvent);
        popup.Location = new Point(parent.Left + 
                            this.Left + 4 ,parent.Top + 
                            this.Bottom + this.Height);
        popup.Show();
        ..........................

The OnDropDown event of the ComboBox is overridden to display our popup from. The popup form should never be a modal, because the popup has to close, if the user decides to click elsewhere other than the grid on the dropdown form. To check where the user has selected something, I use the popup.AfterRowSelectEvent, to fire an event on the MulticolumnComboBox. To use the MulticolumnComboBox do the following:

multiColumnComboBox1.Table = dtable;//DataTable
//Column to display after selection
multiColumnComboBox1.DisplayMember = "Band";
multiColumnComboBox1.ColumnsToDisplay = new 
    string[]{"Band","Song","Album"};//columns to display
//in the dropdown grid

After the DataTable is assigned to the combo, the dropdown looks like this:

After Selection, the DisplayMember of that row is displayed.

The SourceCode is pretty much self-explanatory, download it and try it out.

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

Share

About the Author

SeeSharp
Web Developer
United States United States
Deva Anbu Daniel is an Application Developer with 2+ years experience in Java,VB and C#. Currently working in Insoft.com(www.insoft.com). His favorite language is C. He's a major fan of Iron Maiden and Metallica and Jethro Tull.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
Questioneach column width changed to dynamic?? Pin
MaKhaing2-Aug-15 22:48
memberMaKhaing2-Aug-15 22:48 
Questionmulti column combo Pin
Member 1145351117-Feb-15 9:37
memberMember 1145351117-Feb-15 9:37 
AnswerRe: multi column combo Pin
IssaharNoam24-May-15 10:08
memberIssaharNoam24-May-15 10:08 
QuestionFor selected index changed/ row changed. Pin
joshua89m24-Sep-14 3:45
memberjoshua89m24-Sep-14 3:45 
Questionhow to change so it positions with nested containers Pin
friedmad29-Apr-14 4:46
memberfriedmad29-Apr-14 4:46 
QuestionUnable to download files Pin
Wanda Russell8-Nov-13 4:20
memberWanda Russell8-Nov-13 4:20 
QuestionUnable to download the source code / Demo zip file Pin
Abhijeet Shastry12-Jul-13 2:20
memberAbhijeet Shastry12-Jul-13 2:20 
QuestionCan you make this select the item on Single Click Pin
Manu Kuriachen26-Jun-13 19:38
memberManu Kuriachen26-Jun-13 19:38 
AnswerRe: Can you make this select the item on Single Click Pin
Manu Kuriachen26-Jun-13 19:56
memberManu Kuriachen26-Jun-13 19:56 
QuestionSelectedValue Pin
codeder0017-Jun-13 14:57
membercodeder0017-Jun-13 14:57 
QuestionWhy I can not download this file? Pin
3784722807-Mar-13 19:35
member3784722807-Mar-13 19:35 
Suggestiondon't show the dropdown from the original combobox Pin
andre4710-Sep-12 17:25
memberandre4710-Sep-12 17:25 
GeneralMy vote of 4 Pin
PioneerInfo16-Feb-12 19:09
memberPioneerInfo16-Feb-12 19:09 
QuestionMulticolumn combobox Pin
H123ardie22-Aug-11 22:24
memberH123ardie22-Aug-11 22:24 
GeneralMulticolumn Combobox Pin
Bryan Duchesne30-May-11 8:08
memberBryan Duchesne30-May-11 8:08 
QuestionMultiColumnComboBox1_SelectedIndexChanged is not worked Pin
luyogyi22-Apr-11 8:33
memberluyogyi22-Apr-11 8:33 
GeneralSelectedValue Pin
fariborz sadighi13-Apr-11 21:25
memberfariborz sadighi13-Apr-11 21:25 
GeneralRe: SelectedValue Pin
Member 35985518-May-12 0:33
memberMember 35985518-May-12 0:33 
GeneralRe: SelectedValue Pin
codeder0017-Jun-13 9:45
membercodeder0017-Jun-13 9:45 
QuestionHow do I make this searcheable Pin
BastaNL7-Apr-11 3:22
memberBastaNL7-Apr-11 3:22 
QuestionMultiColumnComboBox1_SelectedIndexChanged and MultiColumnComboBox1_SelectedValueChanged not working Pin
kannan_k718-Mar-11 9:43
memberkannan_k718-Mar-11 9:43 
AnswerRe: MultiColumnComboBox1_SelectedIndexChanged and MultiColumnComboBox1_SelectedValueChanged not working Pin
thatraja26-Jan-12 21:16
mvpthatraja26-Jan-12 21:16 
GeneralHandling F4 key and position of drop down list Pin
kjhduyudmhmxc5-Mar-11 19:00
memberkjhduyudmhmxc5-Mar-11 19:00 
GeneralGood job Pin
RockingDownTheHighway1-Feb-11 15:04
memberRockingDownTheHighway1-Feb-11 15:04 
GeneralGeat job - and this is Multi combobox with C# code Pin
accept Hung18-Sep-08 0:28
memberaccept Hung18-Sep-08 0: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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160811.3 | Last Updated 18 Nov 2002
Article Copyright 2002 by SeeSharp
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid