Click here to Skip to main content
Licence 
First Posted 17 Nov 2002
Views 433,202
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
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  
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  
Questionhow insert Multi Column ComboBox in to DataGridView? Pinmemberaleksey_cherepanov22:10 15 Jan '06  
how insert Multi Column ComboBox in to DataGridView?
AnswerRe: how insert Multi Column ComboBox in to DataGridView? PinmemberTheCrow759:00 16 Jan '06  
GeneralRe: how insert Multi Column ComboBox in to DataGridView? Pinmemberaleksey_cherepanov4:17 19 Apr '06  
NewsBug in Control with mdichild form PinmemberTheCrow757:15 13 Jan '06  
GeneralRe: Bug in Control with mdichild form (simpler fix) Pinmemberbonghi3:25 25 May '07  
GeneralFlicker of Standard ComboBox dropdown still appears Pinmembernathan88818:46 19 Jun '05  
GeneralRe: Flicker of Standard ComboBox dropdown still appears PinPopularmembertjackman4:43 6 Oct '06  
GeneralRe: Flicker of Standard ComboBox dropdown still appears PinmemberNauja16:41 9 Oct '09  
Generaluse MultiColumnComboBox.ValueMember Pinsusskalaj12:06 20 Feb '05  
QuestionHow to get and set value ?? PinmemberInquire2you7:08 23 Sep '04  
Generalmulty column DropDownlist Pinmembersaeednaseh4:18 10 Aug '04  
GeneralRe: multy column DropDownlist PinsussKevin Cochran8:49 15 Sep '04  
GeneralFIX: selectedrow returns nothing PinmemberStefan7523:23 10 Jun '04  
QuestionRe: FIX: selectedrow returns nothing Pinmembermaniatisa2:46 27 Sep '06  
GeneralDropDrownList Style Pinmembercode300510:46 12 Apr '04  
GeneralGet or Set SelectedValue Pinmembercode30057:31 7 Apr '04  
GeneralRe: Get or Set SelectedValue PinmemberDougW4822:04 7 Apr '04  
GeneralRe: Get or Set SelectedValue PinmemberSachin Pisal12:10 14 May '07  
GeneralRe: Get or Set SelectedValue Pinmemberjavadpishvaei1:37 14 Oct '07  

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
Web04 | 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