Winforms data binding: need to know when my data gets saved - winforms

I can't believe I haven't run into this issue before: I have a data bound form and before the user navigates to another record I want to save some additional data from non-bound controls in addition to the bound data. The only event I can find is BindingManagerBase.PositionChanged but this seems to happen after the current record has changed.
Is there a way to get an event when the data has just been saved but before the binding has moved to the new record?

Have you looked at implementing a ListChangedEventHandler to detect when your list changes? The list seems to raise an event of type Reset when the list position changes (assuming your data is in a BindingList<>).

Related

Update data in ComboBox while form is still open

I have form in which I can change the name of stations in my database (SQL Server: in table Stations).
To choose which station I want to edit I've used a combobox.
What I want to happen now is that when I update a station, my ComboBox with stations immediatly gets updated with the edited station.
Is there a way to do this or is this impossible?
I am assuming that this is a Windows Forms application based on the subject. If this is the case, then you have most likely performed databinding, perhaps using a DataTable or a collection, to the ComboBox.
If this is the case, and the object that you have databound supports System.ComponentModel.IBindingList, then all you need to do is add or update the record in the underlying object.
When this happens, the object that has implemented IBindingList sends a message out to any controls that are "listening" and tells them what just happened. The control will then update their data/user interface to reflect these changes.

Refresh ObservableCollection by changes on a remote server

I am fetching data from an URI and parseing the xml to populate my ObservableCollection<"classname"> and showing it on the GridView in my WPF project. The problem I am facing is, when i delete an entry from the ObservableCollection, event is triggered and GridView is updated. However if an entry is updated on the server from which i am getting the data from, no event is triggered on the ObservableCollection and list is not updated.
I have tried reloading the complete object list again on click event but still no changes can be viewed in the GridView. Any idea how to do this?
ObservableCollection only reports adding, removing or replacing items in it. It can't know anything about changes in the internal structure of the stored objects.
If you want changed in your objects reflected in the GUI, you should implement INotifyPropertyChanged.
Alternative approach would be to remove and then add back the item that changed, but it's not as clean as the previous solution.

Flagging changed items in DataServiceCollection (OData)

I've got a Silverlight application that has created a master/detail view of data coming from an OData feed (my first app). When I make changes to an item in the detail view, they are showing up just fine in the master, but the user has no indication on what has changed (including adds & deletes).
For some reason I can't find a property that indicates that the collection has changed. There is a CollectionChanged event, but that's only for items it seems, not for their properties.
Is it possible to easily determine what items have changed in a DataServiceCollection and easily show which ones those are? I expect I could build something that walked through the collection, but that's not idea.
There is INotifyPropertyChanged event, that gets fired when the properties are changed. Does that help?
Thanks
Pratik

How can I stop Silverlight DataForm immediately saving changes back to underlying object?

I have a Silverlight master-details DataForm where the DataForm represents a street address.
When I edit the Address1 textbox, the value gets automatically committed to the bound Address object once focus leaves the textbox.
If I hit the Cancel button, then any changes are undone because Address implements IEditableObject and saves its state.
The problem is that since any change is immediately propagated to the underlying object it will be shown in the master grid before the user has actually hit Save. I also have other locations where this data is shown. This is not a very good user experience.
I've tried OneWay binding but then I can't commit back without manually copying all the fields over.
The only thing I can think of doing is to create a copy of the data first or using OneWay binding, but they both seem a little clumsy.
Does DataForm support this way of working?
The copy of the object feels a little clumsy, but I would use that: it's coming back into style with systems like ASP.NET MVC.
You then also have a good opportunity to do any level of validation you want before commiting it to what will be propagated to other bound controls.

ItemsControl that loads items one by one asynchronously

I am creating a custom DataGrid by deriving the traditional tookit based WPF DataGrid. I want a functionality in the grid to load items one by one asynchronously, wherein as soon as ItemsSource is changed i.e. a new collection is Set to the ItemsSource property or the bound collection is Changed dues to items that rae added, moved or removed (wherein the notifications comes to the data grid when the underlying source implements INotifyCollectionChanged such as ObservableCollection).
This is because even with virtualising stackpanel underneath the datagrid takes time to load (2-3 seconds delay) to load the data rows when it has several columns and some are template based. With above behavior that delay would "appear" to have reduced giving datagrid a feel that it has the data and is responsive enough to load it.
How can I achieve it?
Thx
Vinit.
Sounds like you are looking for data virtualization', which typically means creating your own custom type that resembles IList, and doing a lot of work to hydrate objects after-the-fact.
You will end up having your data that the grid is displaying look something like this:
Index 0: new MyDataObject(0);
Index 1: new MyDataObject(1);
And MyDataObject implements INotifyPropertyChanged.
In the constructor, you do the logic necessary to time, schedule, or interpret when the real results should be read. Until then, you return rather empty data... null and string.Empty from your properties.
Then, once the data becomes available (ideally in a background thread, read from wherever - your own local data, or a database or web service), then you can update the real underlying property values and fire the property change notifications so that the UI gets properly loaded then.
It's a little too complex to just jump into, so some searching will help. Hope this gets you started.

Resources