string cid = dgv.Rows[0].Cells[0].Value.ToString();
for (int i =1; i<dgv.Rows.Count;i++)
{
string x = dgv.Rows[i].Cells[0].Value.ToString();
if(x == cid)
{
dgv.Rows[i].Cells[4].Value =+ 1;
dgv.Rows.RemoveAt(i);
}
else
{
cid= dgv.Rows[i].Cells[0].Value.ToString();
}
}
cid << is checking id
cell[4]<< is quantity (count)default is 1
dgv.Rows[i].Cells[0].Value.ToString();
this line shows,
"System.NullReferenceException: 'Object reference not set to an instance of an object.'"
error when executed.