Private Sub dg_CellValidating(ByVal sender As Object, _ ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dg.CellValidating Dim strErrMsg As String For i = 0 To dg.Rows.Count - 1 dg.Rows(i).ErrorText = "" Next Try With dg If e.ColumnIndex = 0 Then If CStr(e.FormattedValue).Length = 0 Then strErrMsg = "a must entry!" .Rows(e.RowIndex).ErrorText = strErrMsg e.Cancel = True MsgBox("a must entry!", 48, "warning") Else Dim htTable As Hashtable = New Hashtable Dim iRow As Integer Dim sProductID As String Try .Rows(iRow).ErrorText = "" For iRow = 0 To .Rows.Count - 1 sProductID = _ Microsoft.VisualBasic.Left( _ CStr(.Rows(iRow).Cells(0). _ EditedFormattedValue) & Space(4), _ 4) htTable.Add(sProductID, iRow) Next Catch ex As Exception strErrMsg = "a must not duplicate." .Rows(e.RowIndex).ErrorText = strErrMsg e.Cancel = True MsgBox("a must not duplicate!", 48, "warning") End Try End If End If end sub