title: populating text boxes from selected item in combo box
body: <p>I have added a new interface to an existing utility that will read data stored on an external device. This requires taking XML response and deserializing them to a list. Here is the xml and the code for list creation (to copy all element, attribute, type declarations would be too lengthy here.):</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Device&gt;
  &lt;Response&gt;
      &lt;command&gt;Get&lt;/command&gt;
      &lt;argument&gt;AllMethod&lt;/argument&gt;
  &lt;/Response&gt;
  &lt;AllMethod&gt;
  &lt;Method&gt;
      &lt;nMethodNumber&gt;1&lt;/nMethodNumber&gt;
      &lt;sMethodName&gt;Method-8&lt;/sMethodName&gt;
      &lt;fFlowRate&gt;3.00&lt;/fFlowRate&gt;
      &lt;nTubeTemp&gt;250&lt;/nTubeTemp&gt;
      &lt;nTestTime&gt;150&lt;/nTestTime&gt;
  &lt;/Method&gt;
  &lt;Method&gt;
      &lt;nMethodNumber&gt;2&lt;/nMethodNumber&gt;
      &lt;sMethodName&gt;Method-8&lt;/sMethodName&gt;
      &lt;fFlowRate&gt;3.00&lt;/fFlowRate&gt;
      &lt;nTubeTemp&gt;250&lt;/nTubeTemp&gt;
      &lt;nTestTime&gt;150&lt;/nTestTime&gt;
  &lt;/Method&gt;
  &lt;Method&gt;
      &lt;nMethodNumber&gt;3&lt;/nMethodNumber&gt;
      &lt;sMethodName&gt;Method-8&lt;/sMethodName&gt;
      &lt;fFlowRate&gt;3.00&lt;/fFlowRate&gt;
      &lt;nTubeTemp&gt;250&lt;/nTubeTemp&gt;
      &lt;nTestTime&gt;150&lt;/nTestTime&gt;
  &lt;/Method&gt;
  &lt;Method&gt;
      &lt;nMethodNumber&gt;4&lt;/nMethodNumber&gt;
      &lt;sMethodName&gt;Method-8&lt;/sMethodName&gt;
      &lt;fFlowRate&gt;3.00&lt;/fFlowRate&gt;
      &lt;nTubeTemp&gt;250&lt;/nTubeTemp&gt;
      &lt;nTestTime&gt;150&lt;/nTestTime&gt;
  &lt;/Method&gt;
  &lt;Method&gt;
      &lt;nMethodNumber&gt;5&lt;/nMethodNumber&gt;
      &lt;sMethodName&gt;Method-8&lt;/sMethodName&gt;
      &lt;fFlowRate&gt;3.00&lt;/fFlowRate&gt;
      &lt;nTubeTemp&gt;250&lt;/nTubeTemp&gt;
      &lt;nTestTime&gt;150&lt;/nTestTime&gt;
  &lt;/Method&gt;
  &lt;Method&gt;
      &lt;nMethodNumber&gt;6&lt;/nMethodNumber&gt;
      &lt;sMethodName&gt;Method-8&lt;/sMethodName&gt;
      &lt;fFlowRate&gt;3.00&lt;/fFlowRate&gt;
      &lt;nTubeTemp&gt;250&lt;/nTubeTemp&gt;
      &lt;nTestTime&gt;150&lt;/nTestTime&gt;
  &lt;/Method&gt;
  &lt;Method&gt;
      &lt;nMethodNumber&gt;7&lt;/nMethodNumber&gt;
      &lt;sMethodName&gt;Method-8&lt;/sMethodName&gt;
      &lt;fFlowRate&gt;3.00&lt;/fFlowRate&gt;
      &lt;nTubeTemp&gt;250&lt;/nTubeTemp&gt;
      &lt;nTestTime&gt;150&lt;/nTestTime&gt;
  &lt;/Method&gt;
  &lt;Method&gt;
      &lt;nMethodNumber&gt;8&lt;/nMethodNumber&gt;
      &lt;sMethodName&gt;Method-8&lt;/sMethodName&gt;
      &lt;fFlowRate&gt;3.00&lt;/fFlowRate&gt;
      &lt;nTubeTemp&gt;250&lt;/nTubeTemp&gt;
      &lt;nTestTime&gt;150&lt;/nTestTime&gt;
  &lt;/Method&gt;   
  &lt;/AllMethod&gt;
  &lt;/Device&gt;
  </code></pre>
  
  <p>Create List:</p>
  
  <pre><code>public class AllMethod
  {
  [XmlElement("Method")]
  //Puts Methods into list for deserialization.
  public List&lt;Method&gt; methodlist = new List&lt;Method&gt;();
  }
  </code></pre>
  
  <p>I have created the XML document locally to test the functionality of the program before going live. So in my Read Methods button event I have the following code:</p>
  
  <pre><code>private void btnReadMethod_Click(object sender, System.EventArgs e)
  {
          string stringRequestXML = string.Empty;
          string stringResponseXML = string.Empty;
  
  {
          //Will deserialize xml response and populate combo box with method numbers.
          //try
          //{
          XmlSerializer deserializer = new   XmlSerializer(typeof(ReadMethodResponse));
          StreamReader reader = new StreamReader(@"C:\XML\GetAllXml.xml");
          object obj = deserializer.Deserialize(reader);
          ReadMethodResponse XmlData = (ReadMethodResponse)obj;
          reader.Close();
  
  
          //}
          //catch (Exception ex)
          //{
          // throw ex;
          //}
  
          cmbMethodNumber.Items.Clear();
          foreach (Method details in XmlData.allMethods.methodlist)
          {
          cmbMethodNumber.Items.Add(details.MethodNumber);
          }
  
  
  
          }
  
          }
  
      private void cmbMethodNumber_SelectedIndexChanged(object sender, EventArgs e)
      {
          int MethodDetailsIndex = cmbMethodNumber.SelectedIndex;
          Method selectedMethod = xmlData.allMethods.methodlist[MethodDetailsIndex];
          txtMethodName.Text = selectedMethod.MethodName.ToString();
          txtFlow.Text = selectedMethod.FlowRate.ToString();
          txtTubeTemp.Text = selectedMethod.TubeTemp.ToString();
          txtTestTime.Text = selectedMethod.TestTime.ToString();
      }
  
  
  }
  </code></pre>
  
  <p>I have a combobox to display method number and three textboxes to display method name, flow rate, test time, and temp. I am trying to populate the text boxes with the correct information based on the selected value (Method Number) of the combobox. My code for deserializing the xml is functioning fine but I am having trouble populating the text boxes with the corresponding data. I cannot access the list from the cmbMethodNumber_SelectedIndexChanged.
  This is probably fairly simple but I am fairly new to c# and google is not my friend today, any advice?</p>