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
            If e.ColumnIndex = 5 Then
            ElseIf e.ColumnIndex = 6 Then

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

            ElseIf e.ColumnIndex = 8 Then
            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
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
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.