0
votes

I have a question about datagrids I have a datagridview and want some of the cells to be limited to the use of numbers only and other left to accept whatever text the user wants. The idea I came up with is to use a datagrid cell value change event which checks the specified cell to see if it contains a numeric value if so then continue else show message box and reselcet the incorect cell till it dose contain a number my example however just moves on to the other cell how do I fix this?

        MessageBox.Show("Changed")

    Dim HVAL As String
    HVAL = DataGridView2.Rows(2).Cells(1).Value
    If IsNumeric(HVAL) Then
        MsgBox("is number, do nothing")
    Else
        MsgBox("is other than number")
        DataGridView2.Rows(2).Cells(1).Selected = True
        DataGridView2.Rows(2).Cells(1).Style.SelectionBackColor = Color.Crimson
    End If
End Sub
1

1 Answers

0
votes

The datagridview has a built in CellValidation event flow for exactly this, so don't invent your own. To get started look at: Winforms: https://msdn.microsoft.com/en-us/library/7ehy30d4(v=vs.110).aspx The example there shows the basic setup, come back with specific questions if you get stuck.