Easy way to handle combo box in C#

1,Drag & drop Combo box in form in visual studio
2,Assign list like below picture






















3,Assign default value in Combo box when form load

private void Form1_Load(object sender, EventArgs e)
        {
            
            comboBox1.SelectedIndex = 0;
        }
 

4,Double click on combo box will show SelectedIndexChanged event,Use Switch command to write your different event code.

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedIndex){

                case 0: shutdown = "-s"; break;
                case 1: shutdown = "-r"; break;
                case 2: shutdown = "-l"; break;

            
            
            }




No comments:

^ Top