views:

74

answers:

4

Hello, 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.

+1  A: 

DataRow.CancelEdit()
Or
DataRow.RejectChanges()
Or
DataSet.RejectChanges()

Might work in your situation.

Daniel Auger
+1  A: 

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.

Rex M
Just to elaborate little more.I need this functionality to show indicator on the "form" whatever data has changed or not,in the process of editing, not after, so i guess i need to run check whenever bound fields change in any way.
Wally
+1  A: 

You can check the datarow's rowstate property and if Modified then compare the values in the Current and Original DataRowVersions. If your second change makes the value the same as the original then you could call RejectChanges, 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.

AUSteve
A: 

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 :).

        private bool dirty = false;
        private int currentRowIndex;

        void Products_RowChanged(object sender, System.Data.DataRowChangeEventArgs e)
        {
           currentRowIndex=ProductsViewSource.View.CurrentPosition;
            int i=0;
            foreach (object o in originalProducts[currentRowIndex].ItemArray)
            {
                if (o.Equals(restouranDataSet.Products[currentRowIndex].ItemArray[i]))
                    dirty = false;
                else
                {
                    dirty = true;
                    return;
                }
                i++;
            }
        }
Wally