View Single Post
Old 05-29-2019, 07:14 PM   #1
Ryobi
Newly Registered User
 
Join Date: Mar 2012
Posts: 33
Thanks: 1
Thanked 1 Time in 1 Post
Ryobi is on a distinguished road
griddataview duplicate data message

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

Ryobi is offline   Reply With Quote