Click here to Skip to main content
6,594,932 members and growing! (14,943 online)
Email Password   helpLost your password?
Desktop Development » Combo & List Boxes » General     Intermediate

Multi Column ComboBox

By SeeSharp

Displaying Multiple Columns in a Dropdown Combobox
C#.NET 1.0, Win2K, WinXP, Dev
Posted:17 Nov 2002
Views:307,200
Bookmarked:114 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
43 votes for this article.
Popularity: 6.59 Rating: 4.04 out of 5
2 votes, 4.9%
1
3 votes, 7.3%
2
1 vote, 2.4%
3
14 votes, 34.1%
4
21 votes, 51.2%
5

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


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.
Occupation: Web Developer
Location: United States United States

Other popular Combo & List Boxes articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 64 (Total in Forum: 64) (Refresh)FirstPrevNext
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  
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  
GeneralExtra Row and Column? Pinmembertobikage23:38 26 Jun '07  
GeneralCan u write this in Vb.net Pinmembergurdeeptoor1:57 19 Apr '07  
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  
Generalhow insert Multi Column ComboBox in to DataGridView? Pinmemberaleksey_cherepanov23:10 15 Jan '06  
GeneralRe: how insert Multi Column ComboBox in to DataGridView? PinmemberTheCrow7510:00 16 Jan '06  
GeneralRe: how insert Multi Column ComboBox in to DataGridView? Pinmemberaleksey_cherepanov5:17 19 Apr '06  
NewsBug in Control with mdichild form PinmemberTheCrow758:15 13 Jan '06  
GeneralRe: Bug in Control with mdichild form (simpler fix) Pinmemberbonghi4:25 25 May '07  
GeneralFlicker of Standard ComboBox dropdown still appears Pinmembernathan88819:46 19 Jun '05  
GeneralRe: Flicker of Standard ComboBox dropdown still appears Pinmembertjackman5:43 6 Oct '06  
GeneralRe: Flicker of Standard ComboBox dropdown still appears PinmemberNauja17:41 9 Oct '09  
Generaluse MultiColumnComboBox.ValueMember Pinsusskalaj13:06 20 Feb '05  
GeneralHow to get and set value ?? PinmemberInquire2you8:08 23 Sep '04  
Generalmulty column DropDownlist Pinmembersaeednaseh5:18 10 Aug '04  
GeneralRe: multy column DropDownlist PinsussKevin Cochran9:49 15 Sep '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 Nov 2002
Editor: Smitha Vijayan
Copyright 2002 by SeeSharp
Everything else Copyright © CodeProject, 1999-2009
Web19 | Advertise on the Code Project