I would like to populate a combobox with the following:
Visible item / Item Value
English / En Italian / It Spainish / Sp etc....
Any help please?
Also it is possible that after populating the Combobox, to make it read only?
C# ComboBox is a combination of a TextBox and a ListBox control. Only one list item is displayed at one time in a ComboBox and other available items are loaded in a drop down list.
Define a class
public class Language { public string Name { get; set; } public string Value { get; set; } }
then...
//Build a list var dataSource = new List<Language>(); dataSource.Add(new Language() { Name = "blah", Value = "blah" }); dataSource.Add(new Language() { Name = "blah", Value = "blah" }); dataSource.Add(new Language() { Name = "blah", Value = "blah" }); //Setup data binding this.comboBox1.DataSource = dataSource; this.comboBox1.DisplayMember = "Name"; this.comboBox1.ValueMember = "Value"; // make it readonly this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With