Dari : http://www.daniweb.com/software-development/vbnet/threads/334424/datagridview-input-validation-vb.net
Can someone tell me / post some codes here on how could I validate mydatagridview? I mean, a certain column on my datagridview should accept integers only, otherwise, it will return a messagebox. Kindly include on which event it should be posted. Thank you very much. God Bless. :D
Can someone tell me / post some codes here on how could I validate mydatagridview? I mean, a certain column on my datagridview should accept integers only, otherwise, it will return a messagebox. Kindly include on which event it should be posted. Thank you very much. God Bless. :D
Hi!
Check this:
This worked for me without any error:
Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
If (e.ColumnIndex = 1) Then ' Checking numeric value for Column1 only
If DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value <> Nothing Then
Dim value As String = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()
If Not Information.IsNumeric(value) Then
MessageBox.Show("Please enter numeric value.")
DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = String.Empty
Exit Sub
End If
End If
End If
End Sub
Private Sub DataGridView1_DataError(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
MessageBox.Show("Please enter a numeric value")
End Sub
Tidak ada komentar:
Posting Komentar