Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Items to the ComboBox

Tags:

c#

.net

combobox

I have a ComboBox control.

I bind to this control to the DataSet table.

Here is the code:

comboBox.Items.Add(("Select"));
comboBox.DataSource = DataSet.ColorTable;
comboBox.DisplayMember = DataSet.ColorTable.ColorNameColumn.ColumnName;
comboBox.ValueMember = DataSet.ColorTable.ColorIDColumn.ColumnName;

This result I get:

enter image description here

I want to display on the top of the list SELECT: word. So I need to add addition Item to the comboBox control. Here how I implement it:

cmbCategory.Items.Add(("Select"));

But the result is still the same as above. I get only colors without SELECT: word on the top of the list.

Any idea how I can add this string-SELECT: to the ComboBox control and set to this string ValueMember?

like image 643
Michael Avatar asked Dec 12 '22 19:12

Michael


1 Answers

Use Insert method instead.

cmbCategory.Items.Insert(0, "Select");

Note : Put this code after the databind.

like image 77
Kundan Singh Chouhan Avatar answered Dec 30 '22 12:12

Kundan Singh Chouhan