DataRowState.Modified not working

C# - VS2005 - Winforms - SQL2005

I have a bindingNavigator where I'm trying to trap changes before changing records.

I have the bindingNavigator  'Move' properties set to (none).

I open a record and make a change to one of the fields then call this

DataRowView drv = (DataRowView)tblTruckReportBindingSource.List[tblTruckReportBindingSource.Position];

if (drv.Row.RowState == DataRowState.Modified) return (true);

But it never shows that the DataRowState == Modified.

That is, unless I move to another row then move back, then it triggers.

I tried inserting drv.EndEdit(); but that does not help.

What do I need to do to get this to work?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In which event have you placed this code?

Try to call EndEdit() on your bindingsource:


Also, to get the current row of your binding source, use this code:

(tblTruckReportBindingSource.Current as DataRowView).Row as DataRow)
        DataRow row = (tblTruckReportBindingSource.Current as DataRowView).Row as DataRow;
        if (row.RowState == DataRowState.Modified)
            return (true);

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Replace 'DataRow' with your type (typed DataRow)
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

NDennisVAuthor Commented:
"Replace 'DataRow' with your type (typed DataRow)"

Sorry, I don't know what this means.

Your other code runs but always returns Modified = true (exact opposite of original problem).

Forget what I said about replacing 'DataRow'! It is not required in your situation.
Let me explain what I understood:
You open a record, modify a field, and then call that code. Is that true? Then your RowState is surely Modified, because the row is now modified.

You said that you want to trap changes before the change applies to the record. Is this true? Then you should handle ColumnChanging event of your DataTable object.

If you want more explanation, tell me.
And also tell me exactly what you want to do.

Good luck.
NDennisVAuthor Commented:
This code is working:

DataRow row = (tblTruckReportBindingSource.Current as DataRowView).Row as DataRow;
if (row.RowState == DataRowState.Modified) return (true);

Thanks for the help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.