Private Sub StorerBindingNavigatorSaveItem_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles CompanyBindingNavigatorSaveItem.Click save() End Sub Private Sub save() If Not UsergradeDataGridView.Rows(UsergradeDataGridView.Rows.Count - 1).Cells(0).Value Is DBNull.Value And Not UsergradeDataGridView.Rows(UsergradeDataGridView.Rows.Count - 1).Cells(1).Value Is DBNull.Value Then Try Me.Validate() Me.UsergradeBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.WilsonDataSet) Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.SystemModal, "Data error!") Finally End Try Else End If end sub Private Sub UsergradeDataGridView_CellValidating(ByVal sender As Object, _ ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) _ Handles UsergradeDataGridView.CellValidating Dim strErrMsg As String For i = 0 To UsergradeDataGridView.Rows.Count - 1 UsergradeDataGridView.Rows(i).ErrorText = "" Next Try With UsergradeDataGridView If e.ColumnIndex = 0 Then If CStr(e.FormattedValue).Length = 0 Then strErrMsg = "Grade ID must not empty!" .Rows(e.RowIndex).ErrorText = strErrMsg e.Cancel = True MsgBox("Grade ID must not empty!", 48, "Warning") ElseIf CStr(e.FormattedValue).Length > 5 Then strErrMsg = "Grade ID length must not over 5 char" .Rows(e.RowIndex).ErrorText = strErrMsg e.Cancel = True 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(5), _ 5) htTable.Add(sProductID, iRow) Next Catch ex As Exception strErrMsg = "Grade ID must not duplicate!" .Rows(e.RowIndex).ErrorText = strErrMsg e.Cancel = True MsgBox("Grade ID must not duplicate!", 48, "Warning") End Try End If End If If e.ColumnIndex = 1 Then If CStr(e.FormattedValue).Length > 50 Then strErrMsg = "Grade Desc. length must not over 50 char!" .Rows(e.RowIndex).ErrorText = strErrMsg e.Cancel = True MsgBox("Grade Desc. must not over 50 char!", 48, "Warning") End If End If End With Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Information, "User Grade entry error!") End Try End Sub