Hi guys here is my problem. I have 2 datagridview.
What i want to do is whenever i click "add this datagridview1 row(product) to datagridview2" and that product from datagridview1 is already in datagridview2, it will just add the value of a textbox(quantity) to the quantity cell in datagridview2 which have same ID as the one being inserted.
It can already detect if the product your inserting to datagridview2 is already existing but i cant make it add the value of the textbox to the existing cell in the datagridview. Here are my codes(that is wrong and not working) and pic of the datagridviews.
private bool alreadyincart()
{
foreach (DataGridViewRow row in dgvOrdercart.Rows)
{
int productcartID = Convert.ToInt32(dgvOrderproductlist.CurrentRow.Cells[0].Value.ToString());
if (Convert.ToInt32(row.Cells[0].Value) == productcartID)
{
MessageBox.Show("Item already exist, Adding the quantity instead.");
int textboxquantity = Convert.ToInt32(bakss.Text);
int dgvquantity = Convert.ToInt32(row.Cells[3].Value);
int dgvnewquantity;
dgvnewquantity = dgvquantity + textboxquantity;
dgvOrdercart.Rows[productcartID].Cells[3].Value = dgvnewquantity;
return false;
}
}
return true;
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (!validate())
{
return;
}
else if (!alreadyincart())
{
return;
}
else
{
addData(dgvOrderproductlist.CurrentRow.Cells[0].Value.ToString(),
dgvOrderproductlist.CurrentRow.Cells[1].Value.ToString(),
dgvOrderproductlist.CurrentRow.Cells[2].Value.ToString(),
bakss.Text, lblPrice.Text, totalprayss.Text, cboOrderSupplier.SelectedItem.ToString());
}
}
alreadyincart()
returns false when the item is found in the cart, and true when it is not found. That is the opposite of what it should be. – user4843530