Skip to main content
Email Password   helpLost your password?

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.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralGeat job - and this is Multi combobox with C# code Pin
accept Hung
1:28 18 Sep '08  
GeneralCode for set or get value Pin
delphixf
0:00 10 Sep '08  
RantPopup causes main window to loose focus Pin
toidy
23:50 27 May '08  
GeneralRe: Popup causes main window to loose focus Pin
guidol
7:07 28 May '08  
GeneralCode for set or get value Pin
JM ® - DE CASTRO
15:38 29 Apr '08  
GeneralThanks Pin
Fernando Hitch
6:17 14 Jul '07  
GeneralNice control & Smart job but might need Ajax feature incorporated. Pin
mediaplayer
9:50 27 Jun '07  
GeneralExtra Row and Column? Pin
tobikage
23:38 26 Jun '07  
GeneralCan u write this in Vb.net Pin
gurdeeptoor
1:57 19 Apr '07  
GeneralSorting by clicking on the header Pin
joeblew88
6:11 23 Nov '06  
GeneralRe: Sorting by clicking on the header Pin
niuzj
15:24 12 Aug '08  
GeneralPopup & position to selected value Pin
Dhaest
22:19 10 Oct '06  
GeneralGet the location of the popup right Pin
AndersNorell
4:39 4 May '06  
Generalhow insert Multi Column ComboBox in to DataGridView? Pin
aleksey_cherepanov
23:10 15 Jan '06  
GeneralRe: how insert Multi Column ComboBox in to DataGridView? Pin
TheCrow75
10:00 16 Jan '06  
GeneralRe: how insert Multi Column ComboBox in to DataGridView? Pin
aleksey_cherepanov
5:17 19 Apr '06  
NewsBug in Control with mdichild form Pin
TheCrow75
8:15 13 Jan '06  
GeneralRe: Bug in Control with mdichild form (simpler fix) Pin
bonghi
4:25 25 May '07  
GeneralFlicker of Standard ComboBox dropdown still appears Pin
nathan888
19:46 19 Jun '05  
GeneralRe: Flicker of Standard ComboBox dropdown still appears Pin
tjackman
5:43 6 Oct '06  
GeneralRe: Flicker of Standard ComboBox dropdown still appears Pin
Nauja
17:41 9 Oct '09  
Generaluse MultiColumnComboBox.ValueMember Pin
kalaj
13:06 20 Feb '05  
GeneralHow to get and set value ?? Pin
Inquire2you
8:08 23 Sep '04  
Generalmulty column DropDownlist Pin
saeednaseh
5:18 10 Aug '04  
GeneralRe: multy column DropDownlist Pin
Kevin Cochran
9:49 15 Sep '04  


Last Updated 17 Nov 2002 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009