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);
return(false);


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?

Thanks,

Dennis
NDennisVAsked:
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.

DabasCommented:
In which event have you placed this code?

Dabas
0
MDUnicornCommented:
Try to call EndEdit() on your bindingsource:

tblTruckReportBindingSource.EndEdit();

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

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

Open in new window

0

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
MDUnicornCommented:
Comment:
Replace 'DataRow' with your type (typed DataRow)
0
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).

Thanks
0
MDUnicornCommented:
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.
0
NDennisVAuthor Commented:
This code is working:

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

Thanks for the help.
0
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.