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

Get Value of PREVIOUS cell in datagridview

$
0
0
I am using vs2010 and sql. I have a winforms app that has a datagridview on the form. When I enter a row I am trying to get the value from column 1 in the previous row. I need to be able to compare the previous row to the value that will be entered in the current row.

I have tried using the RowEnter like this:
Code:

Private Sub EquipmilesDataGridView_RowEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles EquipmilesDataGridView.RowEnter
        Dim col As Integer = 1
        Dim row As Integer = e.RowIndex
        MsgBox(row)
        Dim prevrow As Integer = e.RowIndex = -1
        MsgBox(prevrow)
        If row <= 0 Then
        Else
            zoldmiles = EquipmilesDataGridView.Rows(prevrow).Cells(1).Value
            MsgBox(zoldmiles)
        End If
End Sub

but it doesn't give me the value. It acts really funny. It will give me the e.rowindex for the first row and then if I click the row again it will give me my current e.rowindex and then it goes back to the first row again and gives me that cell value. Not sure what is happening or if I'm even on the right track here.
Thanks for your help!
Stacy

Viewing all articles
Browse latest Browse all 27072

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>