I have the following enumeration:
|
I have loaded those values to a combo box, but how do i display the value of "MEDIUM" (I.E. M), when i select "MEDIUM" from the combo box?
TY in Advance
|
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Oct 3, 2009, 8:50 AM
You can use Dictionary as same as Enum
look at Below Code That Does the same What you want With Dictionary
Dictionary<string, char> e1;
private void Form1_Load(object sender, EventArgs e)
{
e1 = new Dictionary<string, char>();
e1.Add("LOW", 'L');
e1.Add("MEDIUM", 'M');
e1.Add("HIGH", 'H');
foreach (string str in e1.Keys)
{
comboBox1.Items.Add(str);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach(KeyValuePair<string,char> k in e1)
{
if (k.Key == comboBox1.SelectedItem.ToString())
{
MessageBox.Show(k.Value.ToString());
}
}
}
Roei BarPosted Oct 3, 2009, 7:56 AM
petre ricardoPosted Oct 3, 2009, 6:58 AM
it throws an run time error: Object reference not set to an instance of an Object
Roei BarPosted Oct 3, 2009, 6:37 AM
Dushan StankovicPosted Oct 3, 2009, 5:36 AM