I have searched high and low for an answer to this question and the answers I have found don't generally apply to what I am looking at and was hoping someone might have some suggestions.

I have a form that is bound to a dataset that retrieves its data from a stored procedure. The controls are bound using a table adapter and a binding source.

The form contains many table adapters and binding sources but only one dataset and I'm finding out that in order to do what I want to do, a large drawn out process might be what needs to be done to achieve this.

Basically what I am looking for is a way to place a little asterisk "*" in the title bar of the window when the user makes a change to the data displayed to indicate that the data needs to be saved.

My problem is 2 fold:

1. Finding a method (preferably one that doesn't require me to loop through the entire dataset) that would indicate a change occured to a specific table.

2. Finding an event (preferably just one that I wouldn't have to apply to each and every possible control that the user can edit) that would perform the task above (#1).

This seems like it shouldn't be as difficult as getting the changes for an entire data set using the .HasChanges() method and looping through potentially multiple irrelevant changes when I am only looking for changes to one specific table, and even then, just one specific row.

Even if I have to use the HasChanges() method, I still can't find a useful event to call the method in other than TextChanged for a textbox or CheckedChanged for checkboxes etc... which would call the method a ridiculous number of times and would require subscribing a numerous amount of controls to those events, a task that seems to beg for problems.

Any ideas?

Recommended Answers

All 5 Replies

is the a value/ selected value changed method for the controls you're using ? i used a property grid control to display retrieved data and used SelectedGridItemChanged() to detect a change in the displayed item, then i just set the text of a label when a change occured, i assume you can do this with the title of a form ?


Yes, there are methods like that for the textboxes and checkboxes...as far as I am aware all of the controls that can be databound have an event handler for something like that. But that is precisely what I am trying to avoid.

If I subscribe all of the controls to an event handler like that, that means that each time the data source changes, not because user edited anything, but because the record moved, the events would "fire" causing unnecessary checks and possibly major performance issues. I am aware of the method of using a bool "flag" so to speak to indicate that the events should or should not fire, but that brings up the second issue. If a control is added or removed from the form in the future or later on in the development stages, the new controls would need to also subscribe to those events causing, in my opinion, more maintenance issues and the increased chance for bugs.

I'd prefer if the dataset, or the binding source or table adapter had a method that could be triggered as soon as data was changed.

I'm sure there is a way to do this, but I can't figure it out.

Is there a way to write custom events?

Your binding source should implement the INotifyPropertyChanged interface. Then you'll only need to subscribe to one event.

commented: Yes! +15

Hmmm...Honestly, I read through that link, and I'm completely lost how that applies. The examples and the description at that link imply that if I am binding to a data source manually I would use that. I'm using the BindingSource control from the toolbox that, evidently already, when bound to a SQL server dataset, implements that interface right? If I do BindingSource.SupportsChangeNotification on my binding source it returns true. However, I see no event that I can subscribe to in the binding source called PropertyChanged or anything close to that, just the standards: AddingNew, BindingComplete, CurrentChanged, CurrentItemChanged, DataError, DataMemeberChanged, DataSourceChanged, ListChanged, PositionChanged.

I tried CurrentItemChanged because the MSDN article on the event states:

The CurrentItemChanged event is raised in response to all of the circumstances that raise the CurrentChanged event. Additionally, CurrentItemChanged is also fired whenever the value of one of the properties of Current is changed.

But nothing happens if I change the text in the textbox of any of the bound controls.

Am I missing something or am I making something simple, complicated?

After reading through as much as I could find on the INotifyPropertyChanged interface, I've kinda determined that the amount of work required to implement it is similar to just creating events on every control to catch changes since the interface requires listing each control anyway (or so it appears).

Thanks for the help, I think I'm going to just set up events, unless anyone cares to share a reason why I am wrong in thinking they are similar. Any advantage to one over the other?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.