I have a data grid view and trying to compare data in coloumn 4 with coloumn 6 when data is entered in coloumn 6. but comparision is not happening . How to achive this.

my code

Private Sub DgvAllocate_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DgvAllocate.CellLeave

    Crno = DgvAllocate.CurrentRow.Index

    If e.ColumnIndex = 6 Then

        If DgvAllocate.Rows.Item(Crno).Cells(5).Value() = "X" Then

            If DgvAllocate.Rows.Item(Crno).Cells(4).Value() < DgvAllocate.Rows.Item(Crno).Cells(6).Value Then

                DgvAllocate.Rows.Item(Crno).Cells(6).Value() = DgvAllocate.Rows.Item(Crno).Cells(4).Value
            Else

            End If
        End If

    End If
End Sub

Well the first thing I see you are asking the sub to compare column 6 to column 4 are you aware datagridview columns are a zero based index so column 4 should be 3 and column 6 should be 5. Are you getting any errors or is nothing happening? Have you stepped thru each line of the sub to see if you are getting values into your variables.

index reference is correct.

i tried to check values in message box. it shows the old value and not the new entered value.

Private Sub DgvAllocate_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DgvAllocate.CellLeave

    Crno = DgvAllocate.CurrentRow.Index


    If e.ColumnIndex = 6 Then

        If DgvAllocate.Rows.Item(Crno).Cells(5).Value() = "X" Then

            If DgvAllocate.Rows.Item(Crno).Cells(4).Value() < DgvAllocate.Rows.Item(Crno).Cells(6).Value Then

                DgvAllocate.Rows.Item(Crno).Cells(6).Value() = DgvAllocate.Rows.Item(Crno).Cells(4).Value
            Else
                MsgBox(DgvAllocate.Rows.Item(Crno).Cells(6).Value())
            End If
        End If

    End If
End Sub

You want to call the DataGridVidew EndEdit() method when your cell leave event is fired.

This question has already been answered. Start a new discussion instead.