I can't seem to get this validation routine to work.
Can anyone give me some clues? I thought I was following the proper sequence of events, but I have apparently left something out.
Code:
Private strCellESN As String
Private intNetworkID As Integer
Private Sub dgvRMA_SetDefaultValues(ByVal sender As System.Object, _
ByVal e As DataGridViewRowEventArgs) Handles dgvRMA.DefaultValuesNeeded
With e.Row
'default values for new Equipment row
.Cells(0).Value = 0 'ESN
.Cells(1).Value = cmbCarrier.SelectedValue 'Carrier
.Cells(2).Value = cmbPhone.SelectedValue 'Phone
.Cells(3).Value = cmbColor.SelectedValue 'Color
.Cells(4).Value = cmbLocation.SelectedValue 'Location
.Cells(5).Value = cmbStatus.SelectedValue 'Status
.Cells(6).Value = txtDebitMemoID.Text 'DebitMemo
.Cells(7).Value = "" 'Invoice Nbr
.Cells(8).Value = 0 'RMA Cost
.Cells(9).Value = My.User.Name 'user_insert
.Cells(10).Value = Now() 'date_insert
.Cells(11).Value = My.User.Name 'user_update
.Cells(12).Value = Now() 'date_update
.Cells(13).Value = cmbVendor.SelectedValue 'Customer
End With
End Sub
Private Sub dgvRMA_CellValidating( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms. _
DataGridViewCellValidatingEventArgs) _
Handles dgvRMA.CellValidating
Dim blnValidESN As Boolean
'validate ESN
If e.ColumnIndex = 0 Then
blnValidESN = _
EquipmentNumberValidation(e.ColumnIndex.ToString(), cmbCarrier.SelectedValue)
If Not blnValidESN Then
e.Cancel = True
End If
End If
End Sub
Private Sub dgvRMA_CellEndEdit(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles dgvRMA.CellEndEdit
'clear the error message
dgvRMA.Rows(e.RowIndex).ErrorText = Nothing
End Sub
Private Function GetNetworkType(ByRef intCarrierID As Integer) As Integer
Me.Cursor = Cursors.WaitCursor
' connect to SQL Server
Dim strConn As New SqlConnection(APC_WirelessConnectionString)
strConn.Open()
Dim strSQL As New SqlClient.SqlCommand( _
"SELECT NetworkID from Carrier " & _
" WHERE CarrierID = " & cmbCarrier.SelectedValue & _
";", strConn)
Dim sqlResults As SqlClient.SqlDataReader = strSQL.ExecuteReader()
sqlResults.Read()
intNetworkID = sqlResults("NetworkID")
sqlResults.Close()
strConn.Close()
End Function
Private Function EquipmentNumberValidation(ByRef strCellESN As String, _
ByVal intCarrierID As Integer) _
As Boolean
Dim intStrLen As Integer = Len(strCellESN)
Dim blnNumeric As Boolean
Select Case intNetworkID
Case 1 'CDMA
Select Case intStrLen
Case 8 'Hex
blnNumeric = IsNumeric(Convert.ToInt32(strCellESN, 16))
Case 11 'Decimal
blnNumeric = IsNumeric(Convert.ToInt32(strCellESN, 10))
Case 14 'Hex
blnNumeric = IsNumeric(Convert.ToInt32(strCellESN, 16))
Case Else
blnNumeric = False
End Select
Case 4 'GSM
Select Case intStrLen
Case 10 'Hex
blnNumeric = IsNumeric(Convert.ToInt32(strCellESN, 16))
Case 15 'Decimal
blnNumeric = IsNumeric(Convert.ToInt32(strCellESN, 10))
Case Else
blnNumeric = False
End Select
Case Else
blnNumeric = True
End Select
Return blnNumeric
End Function
The datagridview only contains one cell visible in each row, the ESN.
I am really confused by this.
Please help!
Thanks,
Karen