title: How do I populate a listbox based on a selected item from another listbox?
body: <p>I have two listboxes(Regions and Divisions) when my form loads the Regions listbox is populated with 4 regions(Midwest, NorthEast, South, West). When I click on one of those regions I want the Divisions listbox to populate with the divisions that relate to the region that was clicked. I am working through a data repository that communicates with my SQL db. 
  Initial population upon form load</p>
  
  <pre><code>StateRepository sr = new StateRepository();
  foreach (string s in sr.GetRegions())
  {
      lstRegions.Items.Add(s);
  }
  </code></pre>
  
  <p>Code behind the GetRegions method:</p>
  
  <pre><code>public IEnumerable&lt;string&gt; GetRegions()
  {
      try
      {
          List&lt;string&gt; results = new List&lt;string&gt;();
          using (var conn = new SqlConnection(Settings.Default.StateAnalysisConnection))
          {
              using (var cmd = conn.CreateCommand())
              {
                  cmd.CommandText = "Select * From Regions ";
                  conn.Open();
                  using (var reader = cmd.ExecuteReader())
                  {
                      while (reader.Read())
                      {
                          results.Add((string)reader["Region"]);
                      }
                  }
              }
           }
  
           return results;
      }
      catch (Exception ex)
      {
          throw new Exception("Database error in StateRepository", ex);
      }
      finally
      {
          if (connection.State == ConnectionState.Open)
              connection.Close();
      }
  }
  </code></pre>
  
  <p>The method that gets the divisions in region from the db:</p>
  
  <pre><code>public IEnumerable&lt;string&gt; GetDivisionsInRegion(string region)
  {
      try
      {
          List&lt;string&gt; results = new List&lt;string&gt;();
          var divisions = new List&lt;string&gt;();
          using (var conn = new SqlConnection(Settings.Default.StateAnalysisConnection))
          {
              using (var cmd = conn.CreateCommand())
              {
                   cmd.CommandText = "Select Division From Divisions "
                      + "Where Region = '" + region + "'";
                   conn.Open();
                   using (var reader = cmd.ExecuteReader())
                   {
                       while (reader.Read())
                       {
                           results.Add((string)reader["Division"]);
                       }
                   }
               }
           }
  
           return results;
       }
       catch (Exception ex)
       {
           throw new Exception("Database error in StateRepository", ex);
       }
       finally
       {
           if (connection.State == ConnectionState.Open)
               connection.Close();
       }
  }
  </code></pre>