• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1358
  • Last Modified:

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
0
NDennisV
Asked:
NDennisV
  • 3
  • 2
1 Solution
 
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
 
MDUnicornCommented:
Comment:
Replace 'DataRow' with your type (typed DataRow)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now