I am trying to make combobox with DisplayMember and ValueMember option
I want to discuss the available options to that
Option 1
using DataTable as DataSource and load it into DisplayMember and ValueMember and that option will avoid me the hardcode science data are load it from the database
This option is not applicable in my case for several reason example I have not granted the create table permission
Option 2
using class as shown in this example but that has disadvantage of hardcode
Option 3
using Dictionary as below
Dictionary<string,>test = new Dictionary<string,>();
test.Add("1", "example1");
test.Add("2", "example2");
test.Add("3", "example3");
comboBox1.DataSource = new BindingSource(test, null);
comboBox1.DisplayMember = "Value";
comboBox1.ValueMember = "Key";
// Get combobox selection (in handler)
string value = ((KeyValuePair<string,>)comboBox1.SelectedItem).Value;
to read values back
DictionaryEntry deImgType = (DictionaryEntry)cmbImageType.SelectedItem;
MessageBox.Show(deImgType.Key + ": " + deImgType.Value);
is there any other options? and may this option avoid me the hardcode pelsae ?
Thanks