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

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

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

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.