title: how to set selected value of combo box in C#
body: <p>I have two combo box ( say cbo_zone &amp; cbo_floor ) which are having table as the data source</p>
  
  <pre><code>private void load_cbo_zone() 
      { 
          clz_Common_References ccr = new clz_Common_References ();
          DataTable dt_zone = ccr.get_zone_detail();
          cbo_zone.DataSource = dt_zone;
          cbo_zone.ValueMember = "ID";
          cbo_zone.DisplayMember = "zone";
          cbo_zone.SelectedIndex = -1;
      }
  </code></pre>
  
  <p>` </p>
  
  <pre><code>    private void load_cbo_floor()
      {
          int ID_zone_ref = Convert.ToInt16(cbo_zone.SelectedValue);
          clz_Common_References ccr = new clz_Common_References();
          DataTable dt_flr = ccr.get_floor_data_fr_Ref_IDZone(ID_zone_ref);
          cbo_floor.DataSource = dt_flr;
          cbo_floor.DisplayMember = "Floor";
          cbo_floor.ValueMember = "ID";
          cbo_floor.SelectedIndex = -1;
      }
  </code></pre>
  
  <p>` . I wrote the code to update the cbo_floor as following .</p>
  
  <pre><code>private void cbo_zone_SelectionChangeCommitted(object sender, EventArgs e)
      {
          load_cbo_floor();
      }
  </code></pre>
  
  <p>Now I need to update the cbo_zone &amp; cbo_floor when I click a data row of datagridview .</p>
  
  <pre><code>int ref_area_id, ref_floor_id, ref_zone_id;
  
          int.TryParse(dt_issued_mat.Rows[0][11].ToString(), out ref_area_id);
          DataTable dt_area_detail = ccr.get_area_data_fr_area_id(ref_area_id);
          int.TryParse(dt_area_detail.Rows[0][2].ToString(), out ref_floor_id);
          DataTable dt_floor_detail = ccr.get_floor_data_fr_floor_id(ref_floor_id);
          int.TryParse(dt_floor_detail.Rows[0][2].ToString(), out ref_zone_id);
          DataTable dt_zone_detail = ccr.get_zone_data_fr_zone_id(ref_zone_id);
  </code></pre>
  
  <p>after that using  </p>
  
  <pre><code>cbo_zone.Text  = dt_zone_detail.Rows[0][1].ToString();
  cbo_floor.Text  = dt_floor_detail.Rows[0][1].ToString();
  </code></pre>
  
  <p>I was able to display the values on the combo boxes but once I tried to get the cbo_floor.SelectedValue code doesn't work .</p>
  
  <p>Then I was able to get the relevant SelectedIndex by using ,</p>
  
  <pre><code>int index = cbo_zone.FindString(dt_zone_detail.Rows[0][1].ToString());
          cbo_zone.SelectedIndex  = index ;
  </code></pre>
  
  <p>still the combo box shows nothing &amp; "cbo_zone.SelectedValue"  doesn't
  show a value.my target is to get the cbo_floor.SelectedValue .
  Please help .</p>