title: How to update the target cell of a CurrentRow in DataGridView in C#?
body: <p>In my Windows Form Application, the <code>DataGridView</code> is updated from the <code>TextChanged_Event</code> of a textbox (bar code reading functionality). Every new row has values like <strong>Product Name, Quantity, Unit Price</strong>, and <strong>Total Amount</strong>. The <strong>Product Name</strong> and <strong>Unit Price</strong> values are coming from the database while I have set a default value of 1 for the <strong>Quantity</strong>. The value of <strong>Total Amount</strong> is the multiplication of <em>Quantity</em> and <em>Unit Price</em>.</p>
  
  <p>Everything works fine until now and I am able to use the default 1 value for the sale <strong>Quantity</strong> of each item. However, if I want to sell an item more than once, then I need to replace this default quantity value with a custom value.</p>
  
  <p>To simplify this process, I have used a <strong>Child Form</strong> with a single textbox and a button that will allow my user to put a custom value for the Quantity column which should replace the default 1 value of Quantity column.</p>
  
  <p>I have tried different approaches with no luck. Because <em>I am showing the Child Form at that part of the Sale process where the application has to look for a duplicate product in the DataGridView</em>. If an item is already present in the DataGridView, the application asks for adding it again and when the user clicks on the Yes Button, the <strong>Child Form</strong> is shown.</p>
  
  <p>So it makes my logic meaningless because after showing and making do with the custom Quantity value textbox on the Child Form, I can't access the variable on parent form for replacing its default 1 value with this custom quantity.</p>
  
  <p>My code is working fine but I just need some improvement in the logic so that I can easily replace the default Quantity value with the custom value from the Child Form.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public void FillCurrentSoldItemGrid(string barCode)
      {
          string columnList = "ProductName, UnitPrice";
          DataRow dr = NewSale.SelectByItemCode(columnList, barCode);
          if (dr == null)
          {
              //show error message
              return;
          }
          // check duplicate value in DataGridView
          string productName = dr[0].ToString();
          if (dgvSoldItems.RowCount &gt; 0)
          {
              foreach (DataGridViewRow dgvRow in dgvSoldItems.Rows)
              {
                  if (dgvRow.Cells[0].Value.ToString().CompareTo(productName) == 0)
                  {
                      if (DataAccess.AskUser("This item is already present in the grid?", "Confirm Item Quantity Update") == true)
                      {
              //my child form code
                          using (var customSaleQuantity = new frmCustomSaleQuantity())
                          {
                              var result = customSaleQuantity.ShowDialog();
                              if (result == DialogResult.OK)
                              {
                  //need to assign this value of the customQuantity string to int quantity which is holding a default 1 value)
                                  string customQuantity = customSaleQuantity.GetCustomQuantity;
                              }
                          }
                      }
                  }
              }
          }
      //value of string customQuantity to be assigned to int quantity.
          int quantity = 1;
          int unitPrice = Convert.ToInt32(dr[1]);
  
          DataGridViewRow row = new DataGridViewRow();
          row.CreateCells(dgvAllSoldItems);
  
          row.Cells[0].Value = productName;
          row.Cells[1].Value = quantity;
          row.Cells[2].Value = unitPrice;
          row.Cells[3].Value = (quantity * unitPrice);
  
          dgvAllSoldItems.Rows.Add(row);
      }
  </code></pre>
  
  <p>And here is the code from my Child Form:</p>
  
  <pre><code>public string GetCustomQuantity
      {
          get;
          set;
      }
  
      private void btnProceedWithNewItemQuantity_Click(object sender, EventArgs e)
      {
          this.GetCustomQuantity = txtChooseSaleQuantity.Text.Trim();
          this.Close();
      }
  </code></pre>
  
  <p>I am new to c# and I don't have any idea of how to replace the default 1 value of quantity with the custom value if a duplicate item is detected. This is really important task and my deadline is almost over.</p>
  
  <p>Any help will highly be appreciated.</p>