Link to home
Start Free TrialLog in
Avatar of mgmhicks
mgmhicks

asked on

Settting select cell value from a datagridview

I have the following code.  What I am trying to do is after a cell value has changed from one of these 3 columns, I want to validate data.  If it comes back false I want to go back to the cell that just failed validation.  I have the following code and the validation works, however I cant seem to get it to go back to the unvalidated cell.


thanks in advance

Here is the code

 Private Sub dgv1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv1.CellValueChanged
        Dim myError As String = ""
        If isLoading Then
        Else
            If e.ColumnIndex = 5 Then
                MsgBox("5")
            ElseIf e.ColumnIndex = 6 Then

                If ValidateColumn(dgv1(e.ColumnIndex, e.RowIndex).Value.ToString, e.ColumnIndex, myError) Then
                Else
                    MsgBox(myError)
                    dgv1.CurrentCell = dgv1.Rows(e.RowIndex).Cells(e.ColumnIndex)
                    dgv1.BeginEdit(True)
                    'dgv1.Rows(e.RowIndex).Cells(e.ColumnIndex).Selected = True
                    'dgv1.Select()
                    Exit Sub
                End If

            ElseIf e.ColumnIndex = 8 Then
                MsgBox("7")
            End If
        End If

        
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial