How to check for changes on the BindingSource/DataView, before they are poppulated to Datatables

B

buddha_bg

Hi there,
It's a simple and common scenario, i have a data entry form with two
buttons at bottom 'Apply changes' and 'Cancel'. I use Datasets.
I want to enable/disable these buttons, depending on, if the user has
made a single change to the data in some visual control.
How do i check if there were done any changes through the controls,
which are not yet updated to the dataset.
I must check somehow the BindingSource or its Datasource, which is a
DataView.
None of them have some properties like HasChanges. I cannot even check
for rows in new or edit state.
All these types of methods are available on the Datatable objects, but
the changes are not still poppulated there.
I dont want to call EndEdit everytime a user loses focus on a control
and triggers validation, so i can check the datatables for changes. I
also will not be able to do that when i am inserting a new row.

Hope someone got my question.
Thanks a lot in advance!
 
B

buddha_bg

I think i just figured out, and it seems pretty NICE!
I check the current data row (that i may be editing), for Proposed
version data.
So my strategy to check for data changes on the form is like this:

bool hasChanges = false;
hasChanges =
((DataRowView)myBindingSource.Current).Row.HasVersion(DataRowVersion.Pr
oposed);
--- you may have more binding sources that are editable and check them
also
hasChanges |= myDataSet.HasChanges();

When i apply data changes:
myBindingSource.EndChanges();
tableAdapter.Update(...)

When i cancel changes:
myBindingSource.CancelChanges();
myDataSet.RejectChanges();

Seems its what i was looking for around this alwful dot.net
databinding and shit!
 
G

Guest

There is an event on the binding source CurrentChanged. This fires when the
current index is changed. And CurrentItemChanged which is fried when a
property of the current object is changed through a bound control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top