I have a ComboBox
control which is set to DropDownList
as DropDownStyle
. The control is initialed like below;
List<Sample> samples = new List<Sample>(){
new Sample(),//Empty record
new Sample(){Id = 1, Name = "Sample1"},
new Sample(){Id = 2, Name = "Sample2"}};
// Bind the ComboBox to the list
this.comboBox1.DataSource = samples;
this.comboBox1.DisplayMember = "Name";
this.comboBox1.ValueMember = "Id";
When I set, this.comboBox1.Text = "Sample3";
the drop down doesn't show anything in the text area. It's obvious that Sample3
is not in the underlying DataSource
which is samples
list.
My requirement is to show an item which not in the drop down, but the DropDownStyle
set as DropDownList
. Is it possible?
This is possible when using a ComboBox
that has a DropDownStyle
set to DropDown
.
Note: How do I set a ComboBox default *not in the drop down* when a list item begins with the same text as a drop down item? is not related to the question because OP is using ComboBox
that has a DropDownStyle
set to DropDown
.