Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27329

Keeping focus in the current DataGridView Cell?

$
0
0
I have a DataGridView in which the User is allowed to manually enter data in certain cells. Some of these cells allow for only numeric input. When they enter anything other than numerics, I popup a message indicating so. Then, I wish to keep the focus in the same Cell until a proper value is entered. My problem is that whenever they enter wrong data, it displays the message but advances to the next cell below. How do I keep focus on the cell in error? Below is the code that I am using:

Code:

    Private Sub dgvLoadTests_CellValidated(sender As Object, e As DataGridViewCellEventArgs) Handles dgvLoadTests.CellValidated
        If blnError Then
            blnError = False
            dgvLoadTests.CurrentCell = dgvLoadTests(iRow, iColumn)
        End If
    End Sub

    Private Sub dgvLoadTests_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles dgvLoadTests.CellValueChanged
        Try
            EH.strRetVal = ""

            If Not blnLoading Then
                Dim cell As DataGridViewCell = dgvLoadTests.CurrentCell

                Select Case e.ColumnIndex
                    Case 2
                        If Not IsNumeric(cell.Value) Then
                            iRow = dgvLoadTests.CurrentCell.RowIndex
                            iColumn = dgvLoadTests.CurrentCell.ColumnIndex
                            EH.strRetVal = "Please enter numeric values only!" & "~I"
                            blnError = True
                        End If
                End Select
            End If

        Catch ex As Exception
            EH.strRetVal = gfrmID & "/dgvLoadTests_CellValueChanged() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try

        EH.ProcessMessages(Me, sbr, EH.strRetVal)
    End Sub

thanks,

Viewing all articles
Browse latest Browse all 27329

Trending Articles