Databindings Question
-
I'm programming a windows forms application that retrieves information from a database, binds it to various controls(datagrids, textboxes, datetimepickers,etc.). The binding happens correctly and saving and loading work just fine. An issue, however, has arisen in the need to catch the form before it closes to ask the user if they want to save. Just catching the event and calling the save function if the user wants to save works, but I'm looking for a way to check the data before the dialog box pops, and suppressing the box from showing if there have been no changes. I see this as being potentially doable from one of two places: Within my handler class, which houses the database and the appropriate saving and loading functionality, as well as exposing the tables to the other classes. Within the BindingSource elements(there are about a dozen). The problem is, that I don't see any event or member in each one that I can handle or check to see if the data is different from the original. I tried using a set of foreach loops that loops through every table in the dataset, every row in the table, and checking the RowState parameter, but they remain UnModified, because I don't call EndEdit() on the bindingsources (because I don't think I should do that until I'm actually saving). Obviously, I could handle the Changed event on each control that I bindto, and set a boolean to true anytime after binding, but that seems very overkill and it seems like there should be an easier/better/more efficent way.
-
I'm programming a windows forms application that retrieves information from a database, binds it to various controls(datagrids, textboxes, datetimepickers,etc.). The binding happens correctly and saving and loading work just fine. An issue, however, has arisen in the need to catch the form before it closes to ask the user if they want to save. Just catching the event and calling the save function if the user wants to save works, but I'm looking for a way to check the data before the dialog box pops, and suppressing the box from showing if there have been no changes. I see this as being potentially doable from one of two places: Within my handler class, which houses the database and the appropriate saving and loading functionality, as well as exposing the tables to the other classes. Within the BindingSource elements(there are about a dozen). The problem is, that I don't see any event or member in each one that I can handle or check to see if the data is different from the original. I tried using a set of foreach loops that loops through every table in the dataset, every row in the table, and checking the RowState parameter, but they remain UnModified, because I don't call EndEdit() on the bindingsources (because I don't think I should do that until I'm actually saving). Obviously, I could handle the Changed event on each control that I bindto, and set a boolean to true anytime after binding, but that seems very overkill and it seems like there should be an easier/better/more efficent way.
There are AcceptChanges() function and EndEdit() function. DataSet changes are not commited until AcceptChanges is called, so I'm assuming you can call EndEdit and check the record state of your dataset for changes BEFORE saving the data. You shouldn't call AcceptChanges until you saved the data as it updates the state of your rows (added and edited rows become unchanged, deleted rows are removed) but you can call EndEdit anytime. "Democracy is two wolves and a sheep voting on what to have for dinner" - Ross Edbert Sydney, Australia
-
There are AcceptChanges() function and EndEdit() function. DataSet changes are not commited until AcceptChanges is called, so I'm assuming you can call EndEdit and check the record state of your dataset for changes BEFORE saving the data. You shouldn't call AcceptChanges until you saved the data as it updates the state of your rows (added and edited rows become unchanged, deleted rows are removed) but you can call EndEdit anytime. "Democracy is two wolves and a sheep voting on what to have for dinner" - Ross Edbert Sydney, Australia
Thanks, you helped me find my issue. All of my various usercontrols inhereted a definition for a .Save() method that would call endedit, but in one of them I set flags to mark a "last modified date" field, that was giving me false positives if I was just trying to check. EndEdit() was the end solution though. Thanks.