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

Recommended Answers

All 4 Replies

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.

excelent......thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.