Greeting All,
I have a DataGridView question:
I have a DataGridView that has only one column that the user will use to input data and I want all data entered into this cell to be a number. I am using the following code to check the data entered into the cell during the CellLeave event. The event is firing and I am able to test the cell, but how can I stop the update process once I have tested the cell for a number. Currently, I have the DefaultDataError eventhandler set to do nothing, but it seams there would be a cleaner way.
Thanks for your help.
Code:Private Sub DataGridView3_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView3.CellLeave 'Check for number values only in the Weight cell. Dim int_test As Short If Me.DataGridView3.CurrentCell.ColumnIndex = 2 Then Try int_test = CShort(CStr(Me.DataGridView3.CurrentCell.Value)) 'Test for number values Catch ex As Exception MessageBox.Show("Invalid Weight") Exit Sub End Try End If End Sub Private Sub DataGridView3_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView3.DataError 'do nothing End Sub




Reply With Quote