Как я могу обновить элемент в DataGridView? Если элемент уже существует, я хочу обновить количество. Если элемент не существует, я хочу добавить новую строку.
Вот мой код:
Dim price As Integer = 80
Dim qty As Integer = 1
Dim total As Integer
total = qty * price
Dim food As String = "SISIG"
Dim index As Integer = 0
Dim a As Integer
If DataGridView1.Rows.Count > 0 Then
For a = 0 To DataGridView1.Rows.Count - 1
If DataGridView1.Rows(a).Cells(0).Value = food Then
qty = CInt(DataGridView1.Rows(a).Cells("QUANTITY").Value) + 1
index = a
End If
Next
Else
DataGridView1.Rows.Add(food, qty, price, total)
End If
total = qty * price
DataGridView1.Rows(index).Cells(0).Value = food
DataGridView1.Rows(index).Cells(1).Value = qty
DataGridView1.Rows(index).Cells(2).Value = price
DataGridView1.Rows(index).Cells(3).Value = total