Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am trying to compare a row in a DataGridView before the user gets focus to the row after the user loses focus. I'm doing this to see if anything in the row was changed.

Here's how I am trying to do this:
(Note: dgvPhysCME is the name of the DataGridView control.)

In the Form Class, I have the following temporary rows defined...
VB
Dim rwBefRow As New DataGridViewRow  'Row when focus moves to row
Dim rwAftRow As New DataGridViewRow  'Row when focus leaves row

Then in the RowEnter event, I have...
VB
rwBefRow = CType(dgvPhysCME.Rows(e.RowIndex), DataGridViewRow)

Then in the RowLeave event, I have...
VB
rwAftRow = CType(dgvPhysCME.Rows(e.RowIndex), DataGridViewRow)

When I run this in debug, I can list the "before" values in the RowEnter event just fine. However, once I get into the RowLeave event the "before" values in rwBefRow have been updated to the "current" values so all the values in the rwBefRow are the same as the rwAftRow.

What am I doing wrong?

Thanks, Eddie
Posted
Updated 2-Feb-11 17:55pm
v2

Hi,

Basically what you want is to compare the values in the DataGridViewRow before getting focus and after leaving focus.

DataGridViewRow is a reference type datatype hence when you change value in the row it will modify the instance which u stored in rwBefRow.

Here I guess what you need to do is instead of comparing the full rows you should try to compare the values in that particular row.

I can think of couple of way to implement.
1. Store values of the row somewhere before focus, and in leave event you compare new values in the row to the old values which you stored somewhere.

2. Instead of storing the values, on leave event you compare the values in the row with the values in the datasource to which you are binding your datagridview.

I hope this will help you.

Thanks and regards,
Chetan Ranpariya
 
Share this answer
 
Thanks.

That worked.

Eddie
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900