Guest User

Untitled

a guest
May 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. Private Sub MyForm_CellValidating(ByVal sender As Object, ByVal e As DataGridViewCellValidatingEventArgs) Handles myDGV.CellValidating
  2. Dim dgv As DataGridView = CType(sender, DataGridView)
  3. Select Case dgv.Columns(e.ColumnIndex).Name
  4. Case "uniqueColumn"
  5. ' Validate that the values in our unique column are unique.
  6. For i As Integer = 0 To dgv.RowCount - 1
  7. If i <> e.RowIndex Then
  8. ' Here i != j, so compare to the value...
  9. If e.FormattedValue = dgv.Rows(i).Cells(e.ColumnIndex).FormattedValue Then
  10. e.Cancel = True
  11. 'dgv.ShowRowErrors = True
  12. 'dgv.Rows(e.RowIndex).ErrorText = "Data in the unique column must be unique"
  13. End If
  14. End If
  15. Next 'i
  16. Case Else
  17. ' Perform no validation.
  18. End Select
  19.  
  20. End Sub
  21.  
  22. e.Cancel = True
Add Comment
Please, Sign In to add comment