title: Using combobox with switch statement c#
body: <p>I am trying to use the switch statement in c# to make some text display in a textbox and a number display in another textbox based on the option I select from a combobox. I have made my own class named 'Devices' and have created several objects within the class. I have also given each object several properties (e.g. DeviceName, DeviceRating). However, when I start my form and select an option from my combobox, the first option works as planned (text shows in the relevant text boxes) but all the options display blank textboxes. Any thoughts on why this might be happening?</p>
  
  <p>Here is my code for the properties:</p>
  
  <pre><code> private void Form1_Load(object sender, EventArgs e)
      {
  
          // Gives properties of each object in the 'Devices' class.
  
          WashingMachine.DeviceName = "Washing Machine";
          WashingMachine.DeviceRating = 1200;
  
  
          Dishwasher.DeviceName = "Dishwasher";
          Dishwasher.DeviceRating = 1;
          ;
  
          OvenHob.DeviceName = "Oven/Hob";
          OvenHob.DeviceRating = 1;
          ;
  
          TowelRail.DeviceName = "Towel Rail";
          TowelRail.DeviceRating = 1;
  
  
          Hairdryer.DeviceName = "Hairdryer";
          Hairdryer.DeviceRating = 1;
  
  
          Shower.DeviceName = "Shower";
          Shower.DeviceRating = 1;
  
      }
  </code></pre>
  
  <p>Here is the code for the class I created:</p>
  
  <pre><code>class Devices
      {
          public string DeviceName;
          public int DeviceRating;
          public int UsedMins;
      }
  </code></pre>
  
  <p>Here is code where I create the new objects in the class:</p>
  
  <pre><code>// Creating new objects under the 'Devices' class.
  
      Devices WashingMachine = new Devices();
      Devices Dishwasher = new Devices();
      Devices OvenHob = new Devices();
      Devices TowelRail = new Devices();
      Devices Hairdryer = new Devices();
      Devices Shower = new Devices();
      Devices PhoneCharger = new Devices();
      Devices TabletCharger = new Devices();
      Devices ElectricBlanket = new Devices();
  </code></pre>
  
  <p>And here is the switch statement controlling what happens for each case in the combobox (note that combobox list is in the same order as the listed objects):</p>
  
  <pre><code> // Puts a Name and Power Rating into the textboxes based on the chosen device
      private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
      {
          switch (comboBox1.SelectedIndex)
          {
              case 0:
                  DeviceName.Text = WashingMachine.DeviceName;
                  PowerRating.Text = WashingMachine.DeviceRating.ToString();
                  break;
              case 1:
                  DeviceName.Text = Dishwasher.DeviceName;
                  PowerRating.Text = Dishwasher.DeviceName.ToString();
                  break;
              case 2:
                  DeviceName.Text = OvenHob.DeviceName;
                  PowerRating.Text = OvenHob.DeviceRating.ToString();
                  break;
              case 3:
                  DeviceName.Text = TowelRail.DeviceName;
                  PowerRating.Text = TowelRail.DeviceRating.ToString();
                  break;
              case 4:
                  DeviceName.Text = Hairdryer.DeviceName;
                  PowerRating.Text = Hairdryer.DeviceRating.ToString();
                  break;
              case 5:
                  DeviceName.Text = Shower.DeviceName;
                  PowerRating.Text = Shower.DeviceRating.ToString();
                  break;
          }
  
  
      }
  </code></pre>