title: how to load data into combobox from datagridview
body: <p>I want to load data from datagridview to combobox in another Form to update the problem is that specific item does not being selected in productname combobox against productid what is the solution please help</p>
  
  <pre><code>// Code of gridview form 
  
       private void invoiceItemsDetailsDataGridView_DoubleClick(object sender, EventArgs e)
      {
          int index = invoiceItemsDetailsDataGridView.Rows.GetFirstRow(DataGridViewElementStates.Selected);
          //string productid = invoiceItemsDetailsDataGridView.Rows[index].Cells["ProductId"].Value.ToString();
          //string productName = invoiceItemsDetailsDataGridView.Rows[index].Cells["ProductName"].Value.ToString();
  
          invoiceItemDetailChangeForm icf = new invoiceItemDetailChangeForm();
          icf.CurrentQuantity = Convert.ToUInt16(invoiceItemsDetailsDataGridView.Rows[index].Cells["Quantity"].Value);
          icf.ProductId = Convert.ToUInt16(invoiceItemsDetailsDataGridView.Rows[index].Cells["ProductID"].Value); ;
          icf.ShowDialog();
      }
  </code></pre>
  
  <p>// class level declared int in invoiceItemDetailChangeForm to update </p>
  
  <pre><code>    public int CurrentQuantity { get; set; }
  
      public int ProductId { get; set; }
  </code></pre>
  
  <p>// code related to combobox in invoiceItemDetailChangeForm form</p>
  
  <pre><code>    private void invoiceItemDetailChangeForm_Load(object sender, EventArgs e)
      {
          QtyTextBox.Text = CurrentQuantity.ToString();
          ProductNameComboBox.SelectedValue = ProductId;
  
          ProductNameComboBox.DisplayMember = "ProductName";
          ProductNameComboBox.ValueMember = "ProductID";
          ProductNameComboBox.DataSource = GetAllProducts();
          //ProductNameComboBox.SelectedValue = -1;
  
      }
  
      private object GetAllProducts()
      {
          DataTable dtProducts = new DataTable();
          string connString = ConfigurationManager.ConnectionStrings["dbZ"].ConnectionString;
          using (SqlConnection conn = new SqlConnection(connString))
          {
              using (SqlCommand cmd = new SqlCommand("usp_GetAllProductsForPOS", conn))
              {
                  cmd.CommandType = CommandType.Text;
                  conn.Open();
  
                  SqlDataReader reader = cmd.ExecuteReader();
                  dtProducts.Load(reader);
              }
          }
          return dtProducts;
      }
  </code></pre>