23-04-25, 09:42 PM
جرب الطريقة التالية
PHP كود :
Private Sub DataGridView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
If e.ColumnIndex = 0 Then ' نفترض أن العمود 0 يحتوي على كود الصنف
Dim currentRow As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
Dim currentCode As String = currentRow.Cells(0).Value.ToString()
For i = 0 To DataGridView1.RowCount - 1
If i <> e.RowIndex Then
Dim row As DataGridViewRow = DataGridView1.Rows(i)
If row.Cells(0).Value IsNot Nothing AndAlso row.Cells(0).Value.ToString() = currentCode Then
' صنف مكرر
Dim existingQty As Integer = Val(row.Cells(2).Value) ' نفترض العمود 2 هو الكمية
Dim newQty As Integer = Val(currentRow.Cells(2).Value)
row.Cells(2).Value = existingQty + newQty
' حذف الصف الجديد بأمان
Me.BeginInvoke(New MethodInvoker(Sub()
DataGridView1.Rows.Remove(currentRow)
End Sub))
Exit For
End If
End If
Next
End If
End Sub
