Well, I should not have marked this as resolved so quickly.
When using CellValidating, the TryParse method can not be tested because the cell contents do not exist yet... unless there is a way to read the grid cell contents before the cell is validated. This being the case, there is no point in handling the CellValidating event at all, because the default Grid DataError event will fire if the CellValidating process fails to meet the requirements of the DataTable. Here is the code I am trying now. Am I still missing the bigger picture or is is simply trapping the Grid DataError the correct procedure?
Thanks
Code:Private Sub DataGridView3_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView3.CellValidating 'Check for number values only in the Weight cell. If Me.DataGridView3.CurrentCell.ColumnIndex = 2 Then Dim singleVal As Single Dim result As Boolean Dim str_testString As String = "" If Not Me.DataGridView3.CurrentCell.Value Is Nothing And Not IsDBNull(Me.DataGridView3.CurrentCell.Value) Then str_testString = CStr(Me.DataGridView3.CurrentCell.Value) result = [Single].TryParse(str_testString, singleVal) Console.WriteLine(result & ", " & singleVal.ToString()) If result = False Then MessageBox.Show("Invalid Weight") e.Cancel = True End If End If End If End Sub Private Sub DataGridView3_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView3.DataError MsgBox("Error Trapped") End Sub




Reply With Quote