Hi Mohammed ,
I have made an example for you to make the functionality you are asking for
here is the design as Screen
http://i.imgur.com/yc4s5.jpg[
^]
then here is the code behind of the event Click of the button
Add
bool Found = false;
if (dataGridView.Rows.Count > 0)
{
foreach (DataGridViewRow row in dataGridView.Rows)
{
if (Convert.ToString(row.Cells[0].Value) == textBox_ProductId.Text && Convert.ToString(row.Cells[1].Value) == textBox_Price.Text)
{
row.Cells[2].Value = Convert.ToString(1 + Convert.ToInt16(row.Cells[2].Value));
Found = true;
}
}
if (!Found)
{
dataGridView.Rows.Add(textBox_ProductId.Text, textBox_Price.Text, 1);
}
}
else
{
dataGridView.Rows.Add(textBox_ProductId.Text, textBox_Price.Text, 1);
}