Can someone tell me / post some codes here on how could I validate my datagridview? 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
paulablanca
0
Junior Poster in Training
Recommended Answers
Jump to PostHi!
Check this:
Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit If (e.ColumnIndex = 0) Then ' Checking numeric value for Column1 only Dim value As String = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString() For Each c As Char In value If Not Char.IsDigit(c) Then MessageBox.Show("Please enter …
Jump to PostAnother Alternative using same event:
Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit If (e.ColumnIndex = 0) Then ' Checking numeric value for Column1 only 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 …
Jump to PostHmm... glad to see that your problem "Solved". :)
Please close thread, so that other expert may avoid to comment on it.
Jump to PostYou should write:
e.ColumnIndex = 3since index is zero-based.
If this don't help please post the error message.
Jump to PostThis 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 …
All 18 Replies
ShahanDev
41
Junior Poster
ShahanDev
41
Junior Poster
paulablanca
0
Junior Poster in Training
paulablanca
0
Junior Poster in Training
ShahanDev
41
Junior Poster
paulablanca
0
Junior Poster in Training
ShahanDev
41
Junior Poster
paulablanca
0
Junior Poster in Training
ShahanDev
41
Junior Poster
paulablanca
0
Junior Poster in Training
paulablanca
0
Junior Poster in Training
ShahanDev
41
Junior Poster
ShahanDev
41
Junior Poster
paulablanca
0
Junior Poster in Training
paulablanca
0
Junior Poster in Training
ShahanDev
41
Junior Poster
paulablanca
0
Junior Poster in Training
valeriduss
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.