Can you guys help me how to make this happen? I want to have a row validation for adding of items. I have a datagridview named datagridview1 with columns dgvTxtItemCode, dgvTxtItemDesc and so on. I want to add a validation wherein whenever inputted the same itemcode or item desc a message box will appear saying that it has already added.

So here's my code. It's for my capstone/thesis so I badly need your help. Thanks in advance!

Function isAlreadyAdded(itemCode As String, itemName As String) As Boolean
    Dim bFLAG As Boolean
    For Each r As DataGridViewRow In DataGridView1.Rows
        If r.Cells(0).Value = r.Index = itemCode AndAlso r.Index = itemName Then
            bFLAG = True
            Exit For
        End If
    Next
    Return bFLAG
End Function



  Private Sub AddDelivery_RowValidating(sender As Object, e As DataGridViewCellCancelEventArgs) Handles DataGridView1.RowValidating
    With DataGridView1
        If isAlreadyAdded(.Rows(e.RowIndex).Cells(dgvTxtItemDesc.Name).Value, e.RowIndex) Then
            MessageBox.Show("Item was already added!", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            e.Cancel = True
            Exit Sub
        End If
    End With
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.