Click here to Skip to main content
Click here to Skip to main content

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.

Comments and Discussions

 
QuestionFor selected index changed/ row changed. Pinmemberjoshua89m24-Sep-14 4:45 
Questionhow to change so it positions with nested containers Pinmemberfriedmad29-Apr-14 5:46 
QuestionUnable to download files PinmemberWanda Russell8-Nov-13 5:20 
QuestionUnable to download the source code / Demo zip file [modified] PinmemberAbhijeet Shastry12-Jul-13 3:20 
QuestionCan you make this select the item on Single Click PinmemberManu Kuriachen26-Jun-13 20:38 
AnswerRe: Can you make this select the item on Single Click PinmemberManu Kuriachen26-Jun-13 20:56 
QuestionSelectedValue Pinmembercodeder0017-Jun-13 15:57 
QuestionWhy I can not download this file? Pinmember3784722807-Mar-13 20:35 
Suggestiondon't show the dropdown from the original combobox Pinmemberandre4710-Sep-12 18:25 
GeneralMy vote of 4 PinmemberPioneerInfo16-Feb-12 20:09 
QuestionMulticolumn combobox PinmemberH123ardie22-Aug-11 23:24 
GeneralMulticolumn Combobox PinmemberBryan Duchesne30-May-11 9:08 
QuestionMultiColumnComboBox1_SelectedIndexChanged is not worked Pinmemberluyogyi22-Apr-11 9:33 
GeneralSelectedValue Pinmemberfariborz sadighi13-Apr-11 22:25 
GeneralRe: SelectedValue PinmemberMember 35985518-May-12 1:33 
GeneralRe: SelectedValue Pinmembercodeder0017-Jun-13 10:45 
QuestionHow do I make this searcheable PinmemberBastaNL7-Apr-11 4:22 
QuestionMultiColumnComboBox1_SelectedIndexChanged and MultiColumnComboBox1_SelectedValueChanged not working Pinmemberkannan_k718-Mar-11 10:43 
AnswerRe: MultiColumnComboBox1_SelectedIndexChanged and MultiColumnComboBox1_SelectedValueChanged not working Pinmvpthatraja26-Jan-12 22:16 
GeneralHandling F4 key and position of drop down list Pinmemberkjhduyudmhmxc5-Mar-11 20:00 
GeneralGood job PinmemberRockingDownTheHighway1-Feb-11 16:04 
GeneralGeat job - and this is Multi combobox with C# code Pinmemberaccept Hung18-Sep-08 1:28 
GeneralCode for set or get value Pinmemberdelphixf10-Sep-08 0:00 
RantPopup causes main window to loose focus Pinmembertoidy27-May-08 23:50 
GeneralRe: Popup causes main window to loose focus Pinmemberguidol28-May-08 7:07 
GeneralCode for set or get value PinmemberJM ® - DE CASTRO29-Apr-08 15:38 
GeneralThanks PinmemberFernando Hitch14-Jul-07 6:17 
GeneralNice control & Smart job but might need Ajax feature incorporated. Pinmembermediaplayer27-Jun-07 9:50 
QuestionExtra Row and Column? Pinmembertobikage26-Jun-07 23:38 
QuestionCan u write this in Vb.net Pinmembergurdeeptoor19-Apr-07 1:57 
AnswerRe: Can u write this in Vb.net PinmemberBryan Duchesne30-May-11 9:09 
GeneralSorting by clicking on the header Pinmemberjoeblew8823-Nov-06 6:11 
GeneralRe: Sorting by clicking on the header Pinmemberniuzj12-Aug-08 15:24 
GeneralPopup & position to selected value PinmemberDhaest10-Oct-06 22:19 
GeneralGet the location of the popup right PinmemberAndersNorell4-May-06 4:39 
Questionhow insert Multi Column ComboBox in to DataGridView? Pinmemberaleksey_cherepanov15-Jan-06 23:10 
AnswerRe: how insert Multi Column ComboBox in to DataGridView? PinmemberTheCrow7516-Jan-06 10:00 
GeneralRe: how insert Multi Column ComboBox in to DataGridView? Pinmemberaleksey_cherepanov19-Apr-06 5:17 
NewsBug in Control with mdichild form PinmemberTheCrow7513-Jan-06 8:15 
GeneralRe: Bug in Control with mdichild form (simpler fix) Pinmemberbonghi25-May-07 4:25 
GeneralFlicker of Standard ComboBox dropdown still appears Pinmembernathan88819-Jun-05 19:46 
GeneralRe: Flicker of Standard ComboBox dropdown still appears Pinmembertjackman6-Oct-06 5:43 
GeneralRe: Flicker of Standard ComboBox dropdown still appears PinmemberNauja9-Oct-09 17:41 
Generaluse MultiColumnComboBox.ValueMember Pinsusskalaj20-Feb-05 13:06 
QuestionHow to get and set value ?? PinmemberInquire2you23-Sep-04 8:08 
Generalmulty column DropDownlist Pinmembersaeednaseh10-Aug-04 5:18 
GeneralRe: multy column DropDownlist PinsussKevin Cochran15-Sep-04 9:49 
GeneralFIX: selectedrow returns nothing PinmemberStefan7511-Jun-04 0:23 
QuestionRe: FIX: selectedrow returns nothing Pinmembermaniatisa27-Sep-06 3:46 
GeneralDropDrownList Style Pinmembercode300512-Apr-04 11:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web04 | 2.8.150123.1 | Last Updated 18 Nov 2002
Article Copyright 2002 by SeeSharp
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid