Using Enumeration types in switch-case block and ComboBox in C#
Here’s a code snippet that demonstrates how to use enum types in a switch-case block in combination with the ComboBox control. Just wanted to share ’cause I had to look it up on the web. Hope it helps somebody.
using System;
using System.Windows.Forms;
using System.Diagnostics;
namespace EnumWithCombo
{
public partial class PlayerSelectionForm : Form
{
private enum Players
{
Gibbs, Richards, Cronje, Kirsten, Kallis, Smith, Villiers, Pollock, Ntini, Klusener, Steyn, Rhodes, Bosman, Kemp, Botha, Harris, Roelof
}
private string url = "http://www.cricinfo.com/ci/content/player/45224.html";
public PlayerSelectionForm()
{
InitializeComponent();
playersComboBox.DataSource = Enum.GetValues(typeof(Players));
}
private void submitButton_Click(object sender, EventArgs e)
{
switch ((Players) playersComboBox.SelectedItem)
{
case Players.Gibbs:
Process.Start(new ProcessStartInfo("iexplore", url));
break;
default:
MessageBox.Show(((Players) playersComboBox.SelectedItem).ToString());
break;
}
}
}
}
Posted: June 17th, 2009
at 5:08am by Kayes
Tagged with C#, combobox, enum, switch-case
Categories: C#
Comments: 1 comment
One Response to 'Using Enumeration types in switch-case block and ComboBox in C#'
Subscribe to comments with RSS or TrackBack to 'Using Enumeration types in switch-case block and ComboBox in C#'.

Thnks bro!
Robin
31 May 10 at 11:30 am