Click here to Skip to main content
Licence 
First Posted 17 Nov 2002
Views 419,594
Downloads 14,780
Bookmarked 148 times

Multi Column ComboBox

By SeeSharp | 17 Nov 2002
Displaying Multiple Columns in a Dropdown Combobox
2 votes, 4.4%
1
3 votes, 6.7%
2
1 vote, 2.2%
3
14 votes, 31.1%
4
25 votes, 55.6%
5
4.57/5 - 47 votes
5 removed
μ 4.10, σa 1.93 [?]

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
QuestionMulticolumn combobox PinmemberH123ardie23:24 22 Aug '11  
GeneralMulticolumn Combobox PinmemberBryan Duchesne9:08 30 May '11  
QuestionMultiColumnComboBox1_SelectedIndexChanged is not worked Pinmemberluyogyi9:33 22 Apr '11  
GeneralSelectedValue Pinmemberfariborz sadighi22:25 13 Apr '11  
QuestionHow do I make this searcheable PinmemberBastaNL4:22 7 Apr '11  
QuestionMultiColumnComboBox1_SelectedIndexChanged and MultiColumnComboBox1_SelectedValueChanged not working Pinmemberkannan_k710:43 18 Mar '11  
AnswerRe: MultiColumnComboBox1_SelectedIndexChanged and MultiColumnComboBox1_SelectedValueChanged not working Pinmvpthatraja22:16 26 Jan '12  
GeneralHandling F4 key and position of drop down list Pinmemberkjhduyudmhmxc20:00 5 Mar '11  
GeneralGood job PinmemberRockingDownTheHighway16:04 1 Feb '11  
GeneralGeat job - and this is Multi combobox with C# code Pinmemberaccept Hung1:28 18 Sep '08  
GeneralCode for set or get value Pinmemberdelphixf0:00 10 Sep '08  
RantPopup causes main window to loose focus Pinmembertoidy23:50 27 May '08  
GeneralRe: Popup causes main window to loose focus Pinmemberguidol7:07 28 May '08  
Hi toidy,
 
i have the same Problem. When you (anyone) find a solution pleace post it.
 
thanks a lot
 
guido
GeneralCode for set or get value PinmemberJM ® - DE CASTRO15:38 29 Apr '08  
GeneralThanks PinmemberFernando Hitch6:17 14 Jul '07  
GeneralNice control & Smart job but might need Ajax feature incorporated. Pinmembermediaplayer9:50 27 Jun '07  
QuestionExtra Row and Column? Pinmembertobikage23:38 26 Jun '07  
QuestionCan u write this in Vb.net Pinmembergurdeeptoor1:57 19 Apr '07  
AnswerRe: Can u write this in Vb.net PinmemberBryan Duchesne9:09 30 May '11  
GeneralSorting by clicking on the header Pinmemberjoeblew886:11 23 Nov '06  
GeneralRe: Sorting by clicking on the header Pinmemberniuzj15:24 12 Aug '08  
GeneralPopup & position to selected value PinmemberDhaest22:19 10 Oct '06  
GeneralGet the location of the popup right PinmemberAndersNorell4:39 4 May '06  
Questionhow insert Multi Column ComboBox in to DataGridView? Pinmemberaleksey_cherepanov23:10 15 Jan '06  
AnswerRe: how insert Multi Column ComboBox in to DataGridView? PinmemberTheCrow7510:00 16 Jan '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
Web02 | 2.5.120210.1 | Last Updated 18 Nov 2002
Article Copyright 2002 by SeeSharp
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid