I have the following enumeration:
Code Code Code |
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
Code Code Code |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dushan Stankovic72 reputationPosted Oct 3, 2009, 1:36 AM EDT
Roei BarRank #1,271 · 1.4K reputationPosted Oct 3, 2009, 2:37 AM EDT
petre ricardo155 reputationPosted Oct 3, 2009, 2:58 AM EDT
it throws an run time error: Object reference not set to an instance of an Object
Roei BarRank #1,271 · 1.4K reputationPosted Oct 3, 2009, 3:56 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 3, 2009, 4:50 AM EDT
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());
}
}
}