I'll try to explain. I want to track dirty records in my dataset row that is bound to controls on window (wpf).
It works fine. Lets say i begin to edit some textbox that is bound to dataTable in that dataSet. After i add one character to textbox, dataset is marked dirty.
But if I delete that character again ( restore original value ), dataset is still dirty. I want after i restore original value to dataSet become not dirty, because in reallity it isn't dirty any more.
Is there any method i need to call so dataset can recompute dirty records from binding fields, or some similar aproach. Thanks.
You need to keep a copy of the original entity set to compare against, and make the "IsDirty" determination at the point you actually need to know whether it's dirty, not at the point the data is changed and therefore only might be dirty.
You can check the datarow's
rowstate
property and ifModified
then compare the values in theCurrent
andOriginal
DataRowVersions. If your second change makes the value the same as the original then you could callRejectChanges
, but that would reject ALL changes on that row. You will have to manually track each field since the dataset only keeps per-row or per-table changes and any change is a change, even if you set the same value.Well, got something working, just wanted to share. So far so good. Thanks everyone for answers, helped me alot. Next step is building this functionality into custom control :).
DataRow.CancelEdit()
Or
DataRow.RejectChanges()
Or
DataSet.RejectChanges()
Might work in your situation.