griddataview duplicate data message (1 Viewer)

Ryobi

Registered User.
Local time
Yesterday, 19:55
Joined
Mar 5, 2012
Messages
49
Hello,


I have this issue that perhaps somebody can solve using a gridataview in Vb,net. The column of cells need to be unique, so I am checking for duplicates when the cells are changed or added. If the cell are duplicates then I want to cell to be reverted to the old value. I have my code below


For Each row In DgvDataRecords.Rows
If ItemName = row.Cells("Card ID").Value Then
Itemcnt = Itemcnt + 1
If Itemcnt > 1 Then
' MessageBox.Show("Item already exists, can not be add. ")
DgvDataRecords.CurrentCell.Value = Oldvalue
Exit Sub

End If
If Itemcnt = 1 Then
Rowfound = DgvDataRecords.Rows.IndexOf(row)
End If
End If
Next



The code works except that I want to put a message to tell the user that the cells are duplicate. This the remarked line ' MessageBox.Show("Item already exists, can not be add. "). The problem that I have is that when the old value is restored the error message is displayed again as it was part the cell. Is there a way to suppress the second error message ?


Thank you
 

rpeare

Registered User.
Local time
Yesterday, 17:55
Joined
Sep 15, 2016
Messages
18
Instead of displaying the message box immediately, you can store an 'errorsfound' variable (1 or 0) then at the end of your code running display the message box if the errorsfound value is non zero. Would also allow you do things like capture all the errors on your form and display them in a single message as opposed to getting a pop up for each error encountered.
 

Ryobi

Registered User.
Local time
Yesterday, 19:55
Joined
Mar 5, 2012
Messages
49
Thank you for the information. You are correct about a single error message, that is what I was trying to do, however my dilemma is that I need to stop when it get the one that I that is being checked (the current record) or by pass that in case the current record is not a new record. Hope this makes sense.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom