Start New Discussion within our Software Development Community

I have a DataGridView control and I want to know if the user has changed any data in the row when they leave one row and go to another row. Here's what I've done...

In the Form Class I defined a Before and After row image as follows:

Dim rwBefRow As New DataGridViewRow 'Before row image
Dim rwAftRow As New DataGridViewRow 'After row image

Then in the DataGridView_RowEnter event I copied the row to rwBefRow before the user gets control as follows:

rwBefRow = CType(dgvPhysCME.Rows(e.RowIndex), DataGridViewRow)

In the DataGridView_RowLeave event, I copied the row to rwAftRow after the user makes any changes as follows:

rwAftRow = CType(dgvPhysCME.Rows(e.RowIndex), DataGridViewRow)

At this point, when I look at rwBefRow, it contains the data in the row AFTER I make them. It's like when the RowLeave event fires, it also fires the RowEnter. I put a breakpoint at the RowEnter event and it gets control only when a row is entered, as you would expect.

What can I do to keep the rwBefRow values unchanged when I get to the RowLeave event?

Any help would be appreciated. Eddie

Here's the solution. The method was trying to use here isn't appropriate. The reference to "Dim xxx as New DataGridViewRow" get re-evaluated whenever it is referenced. Instead, I needed to save the value of each cell when the row is entered (RowEnter event) and then again when the row is exited (RowLeave event). When I compare each cell value, if any is changed, I can update that row in the database with the new values.

Thanks for everyones input. Eddie

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