0

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
2
Contributors
1
Reply
11
Views
1 Year
Discussion Span
Last Post by Mr.M
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.