0

Hi,
I have a datagridview on my form.There is a column of roll no in the datagridview.
I want that whenever user presses anyother key than a number key(ex:1,2,3,4....)than immediately i should get a messagebox that only numbers allowed.
I have tried the below code on datagridView Cellvalidation event but its not working.
Please suggest on what event and how can i do such validation.

If GridView2.Item(2, GridView2.CurrentCell.RowIndex).Selected = True Then
            If e.ColumnIndex = 3 Then
                If Not IsNumeric(e.FormattedValue) Then
                    GridView2.Rows(e.RowIndex).ErrorText = _
                       "Please Insert only numbers."
                    e.Cancel = True
                End If
            End If
        End If
2
Contributors
6
Replies
17
Views
6 Years
Discussion Span
Last Post by Ehtesham Siddiq
0

Try your code in Cell Enter event, cell leave event and see. And if Not valid entry then dont forget to clear the cell.

0

m getting error on e.FormattedValue as FormattedValue is not a member of System.Windows.Forms.DataGridViewCellEventArgs

0

Why ur doing E.formatedvalue? instead you can get the cell text using Activecell.text right?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.