title: Programmatically select an item in combobox by using its ValueMember property
body: <p>I have a method that gets the <code>ComboBox</code> object and the query to be loaded on its items.</p>
  
  <p>The method also asks for 2 other items:</p>
  
  <p>1.The DB table's column name and sets it into the <code>Combobox</code>'s <code>DisplayMember</code> property</p>
  
  <p>2.The id of each record under that DB table column name and sets it into the <code>Combobox</code>'s <code>ValueMember</code> property</p>
  
  <pre><code>public void DatabaseColumnRecordsToCombobox(ComboBox cbx, String query, String displayMember, String valueMember)
  {
      try
      {
          cmd = new MySqlCommand(query, connection);
          da = new MySqlDataAdapter(cmd);
          tbl = new DataTable();
          da.Fill(tbl);
          cbx.DataSource = tbl;
          cbx.DisplayMember = displayMember;
          cbx.ValueMember = valueMember;
      }
      catch (Exception ex)
      {
          MessageBox.Show(ex.Message);
      }
      finally
      {
          this.CloseConnection();
      }
  }
  </code></pre>
  
  <p>I use the method by creating a query with 2 columns, the Id and its corresponding Name. And storing it in the <code>ComboBox</code>'s <code>DisplayMember</code> and <code>ValueMember</code>:</p>
  
  <pre><code>DatabaseColumnRecordsToCombobox(cmbSupplier, "SELECT Id, Supplier_Name FROM Supplier WHERE Enable_Flag=1 ORDER BY Supplier_Name", "Supplier_Name", "Id");
  </code></pre>
  
  <p>I apologize for the long introduction, I just want you all to understand how my program works before telling my problem. So the problem is how do I select the default item of <code>DataGridView</code> by using the <code>ComboBox</code>'s <code>ValueMember</code> property?</p>
  
  <p>All I know in programatically selecting an item is by using <code>cmbCategory.SelectedItem = "Supplier A"</code> but what I need is to select by using the <code>ValueMember</code>. This way I can set the default item by Id.</p>