0
       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.

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
  • 2
    Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Lucifer Mar 16 '20 at 10:59
  • you should check `(dgv.Rows[i].Cells[0].Value != null)` – Lucifer Mar 16 '20 at 11:02

0 Answers0