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

 
Questionhow to change so it positions with nested containers Pinmemberfriedmad29-Apr-14 4:46 
QuestionUnable to download files PinmemberWanda Russell8-Nov-13 4:20 
QuestionUnable to download the source code / Demo zip file [modified] PinmemberAbhijeet Shastry12-Jul-13 2:20 
QuestionCan you make this select the item on Single Click PinmemberManu Kuriachen26-Jun-13 19:38 
AnswerRe: Can you make this select the item on Single Click PinmemberManu Kuriachen26-Jun-13 19:56 
QuestionSelectedValue Pinmembercodeder0017-Jun-13 14:57 
QuestionWhy I can not download this file? Pinmember3784722807-Mar-13 19:35 
Suggestiondon't show the dropdown from the original combobox Pinmemberandre4710-Sep-12 17:25 
GeneralMy vote of 4 PinmemberPioneerInfo16-Feb-12 19:09 
QuestionMulticolumn combobox PinmemberH123ardie22-Aug-11 22:24 
GeneralMulticolumn Combobox PinmemberBryan Duchesne30-May-11 8:08 
QuestionMultiColumnComboBox1_SelectedIndexChanged is not worked Pinmemberluyogyi22-Apr-11 8:33 
GeneralSelectedValue Pinmemberfariborz sadighi13-Apr-11 21:25 
GeneralRe: SelectedValue PinmemberMember 35985518-May-12 0:33 
GeneralRe: SelectedValue Pinmembercodeder0017-Jun-13 9:45 
QuestionHow do I make this searcheable PinmemberBastaNL7-Apr-11 3:22 
QuestionMultiColumnComboBox1_SelectedIndexChanged and MultiColumnComboBox1_SelectedValueChanged not working Pinmemberkannan_k718-Mar-11 9:43 
AnswerRe: MultiColumnComboBox1_SelectedIndexChanged and MultiColumnComboBox1_SelectedValueChanged not working Pinmvpthatraja26-Jan-12 21:16 
GeneralHandling F4 key and position of drop down list Pinmemberkjhduyudmhmxc5-Mar-11 19:00 
GeneralGood job PinmemberRockingDownTheHighway1-Feb-11 15:04 
GeneralGeat job - and this is Multi combobox with C# code Pinmemberaccept Hung18-Sep-08 0:28 
GeneralCode for set or get value Pinmemberdelphixf9-Sep-08 23:00 
RantPopup causes main window to loose focus Pinmembertoidy27-May-08 22:50 
GeneralRe: Popup causes main window to loose focus Pinmemberguidol28-May-08 6:07 
GeneralCode for set or get value PinmemberJM ® - DE CASTRO29-Apr-08 14:38 

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 | Mobile
Web03 | 2.8.140814.1 | Last Updated 18 Nov 2002
Article Copyright 2002 by SeeSharp
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid