troubleshooting Question

Sorting a datagrid view loses ability to obtain original values

Avatar of LenTompkins
LenTompkinsFlag for United States of America asked on
.NET Programming
3 Comments1 Solution439 ViewsLast Modified:
I have a windows app where I would like to compare the original value of the table to the value in the grid.  I had written code to do this in the following manner:
             int rowIndex = this.dgvReferralDistinct.CurrentRow.Index;
            DataRow row = this.m_dsReferral.ReferralGroupDistinct.Rows[rowIndex];
            string origRefGrouping = row["RefGroup", DataRowVersion.Original].ToString();
            string origSalesRep = row["SalesRep", DataRowVersion.Original].ToString();
This code works great until a user sorts the grid.  Then the indexes do not match the dataset.
What is the proper way to find the original value for comparison purposes?  
Do I need to reselect the row from the database based on the key or can I add the value twice, once as viewable and changable and again where it is not visible?
Thank you in advance.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros