Hi,
How to create multi-column combo box in vb.net?
This combo box should have 2 or more columns like that!
Printable View
Hi,
How to create multi-column combo box in vb.net?
This combo box should have 2 or more columns like that!
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.
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:Code: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();
http://www.codeproject.com/KB/combob...lumncombo.aspxCode: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
I hope this helps you!
If U have ur field names as follows:
Firsname Lasname ,ID
U need to know that, There 're two types of combo box
1. A combo box -Normal
2. a data combo
Thee First one, u will have it as
yo will have to decare a recordset to select Firstname, lastname and a id from the table that house those records:
eg
dim rst as new adodb.recordset
dim conn as new adodb.connection
conn.open("dsn=datasourcename")
set rst = conn.execute ("select Firstname, lastname ,Id from tablename ")
do until rst.eof
combo1.Additem rst!firstname +' '+ rst!Lastname +' ' rst!ID
rst.movenext
loop
The second one uses Ado data control
Where u will have the Ado datacontrol selecting as thus:
select firstname +' '+ rst!Lastname +' ' rst!ID from tablename
i hope u will get it