Click here to Skip to main content
Licence 
First Posted 17 Nov 2002
Views 433,301
Bookmarked 151 times

Multi Column ComboBox

By | 17 Nov 2002 | Article
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

About the Author

SeeSharp

Web Developer

United States United States

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 4 PinmemberPioneerInfo19:09 16 Feb '12  
QuestionMulticolumn combobox PinmemberH123ardie22:24 22 Aug '11  
GeneralMulticolumn Combobox PinmemberBryan Duchesne8:08 30 May '11  
QuestionMultiColumnComboBox1_SelectedIndexChanged is not worked Pinmemberluyogyi8:33 22 Apr '11  
GeneralSelectedValue Pinmemberfariborz sadighi21:25 13 Apr '11  
GeneralRe: SelectedValue PinmemberMember 35985510:33 8 May '12  
QuestionHow do I make this searcheable PinmemberBastaNL3:22 7 Apr '11  
QuestionMultiColumnComboBox1_SelectedIndexChanged and MultiColumnComboBox1_SelectedValueChanged not working Pinmemberkannan_k79:43 18 Mar '11  
AnswerRe: MultiColumnComboBox1_SelectedIndexChanged and MultiColumnComboBox1_SelectedValueChanged not working Pinmvpthatraja21:16 26 Jan '12  
GeneralHandling F4 key and position of drop down list Pinmemberkjhduyudmhmxc19:00 5 Mar '11  
GeneralGood job PinmemberRockingDownTheHighway15:04 1 Feb '11  
GeneralGeat job - and this is Multi combobox with C# code Pinmemberaccept Hung0:28 18 Sep '08  
GeneralCode for set or get value Pinmemberdelphixf23:00 9 Sep '08  
RantPopup causes main window to loose focus Pinmembertoidy22:50 27 May '08  
GeneralRe: Popup causes main window to loose focus Pinmemberguidol6:07 28 May '08  
GeneralCode for set or get value PinmemberJM ® - DE CASTRO14:38 29 Apr '08  
GeneralThanks PinmemberFernando Hitch5:17 14 Jul '07  
GeneralNice control & Smart job but might need Ajax feature incorporated. Pinmembermediaplayer8:50 27 Jun '07  
QuestionExtra Row and Column? Pinmembertobikage22:38 26 Jun '07  
QuestionCan u write this in Vb.net Pinmembergurdeeptoor0:57 19 Apr '07  
AnswerRe: Can u write this in Vb.net PinmemberBryan Duchesne8:09 30 May '11  
GeneralSorting by clicking on the header Pinmemberjoeblew885:11 23 Nov '06  
Hi,
 
does anyone know how to modify this code to get the the columns to sort when I click on the column header?
 

GeneralRe: Sorting by clicking on the header Pinmemberniuzj14:24 12 Aug '08  
GeneralPopup & position to selected value PinmemberDhaest21:19 10 Oct '06  
GeneralGet the location of the popup right PinmemberAndersNorell3:39 4 May '06  

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.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 18 Nov 2002
Article Copyright 2002 by SeeSharp
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid