kimprogrammer
Programmer
Hello
I have a datagrid and would like to validate one field. I've copied some code from someone elses thread and made some changes.
When I select data from my first combo box (not part of the datagrid) I get this error and shouldn't.
I am new to vb and am teaching myself so I'd appreciate help in understanding how cell validation works.
Here is my code:
Private Sub SwipeAccumulativeHoursDataGridView_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles SwipeAccumulativeHoursDataGridView.CellValidating
If SwipeAccumulativeHoursDataGridView.Columns(e.ColumnIndex).DataPropertyName <> "" Then
Try 'check if numeric
SwipeAccumulativeHoursDataGridView.Columns(e.ColumnIndex).DataPropertyName = Decimal.Parse(SwipeAccumulativeHoursDataGridView.Columns(e.ColumnIndex).DataPropertyName)
Catch ex As Exception
e.Cancel = True
MessageBox.Show("Amount - Must enter a numeric field", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
SwipeAccumulativeHoursDataGridView.Columns(e.ColumnIndex).DataPropertyName = ""
End Try
End If
End Sub
Thanks
Kim
I have a datagrid and would like to validate one field. I've copied some code from someone elses thread and made some changes.
When I select data from my first combo box (not part of the datagrid) I get this error and shouldn't.
I am new to vb and am teaching myself so I'd appreciate help in understanding how cell validation works.
Here is my code:
Private Sub SwipeAccumulativeHoursDataGridView_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles SwipeAccumulativeHoursDataGridView.CellValidating
If SwipeAccumulativeHoursDataGridView.Columns(e.ColumnIndex).DataPropertyName <> "" Then
Try 'check if numeric
SwipeAccumulativeHoursDataGridView.Columns(e.ColumnIndex).DataPropertyName = Decimal.Parse(SwipeAccumulativeHoursDataGridView.Columns(e.ColumnIndex).DataPropertyName)
Catch ex As Exception
e.Cancel = True
MessageBox.Show("Amount - Must enter a numeric field", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
SwipeAccumulativeHoursDataGridView.Columns(e.ColumnIndex).DataPropertyName = ""
End Try
End If
End Sub
Thanks
Kim