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

Visual Basic.NETVB Script.NET Programming

Avatar of undefined
Last Comment
Nasir Razzaq

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Nasir Razzaq

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61