views:

773

answers:

7

Hi , I have WPF listview bound to collection of objects. Objects are continuously added in to collection from remote server and same is reflecting in to listview. Now we have requirement that we should be able to freeze listview for some time, That is objects should still get added in to collection but should not appear in listview till we unfreeze it ( we have button to freeze and unfreeze) . What is the best way to do it, when listview is bound to collection ? How to unbind collection and rebind it ? and Will i still able to filter and sort when collection is unbound from listview ? Waiting for answer please reply

Regards Sandeep

A: 

You should just stop updating the collection when the list is frozen, if you must keep adding to the collection even when the list is frozen (if the same collection is used somewhere else that shouldn't be frozen) then consider having two collections, one always updated and the other one bound to the listview.

Nir
A: 

What is the list type you are using as the data-source? Can you use BindingList<T>? If so, this has a settable RaiseListChangedEvents property, allowing you to turn off notifications. This will probably get very messy re your last points, though (sort/filter).

Personally, I'd work with 2 lists - the bound one, and the one that the server is updating. When paused, simply stop pumping data between the two. This should leave the paused view free for sorting / filtering etc.

Marc Gravell
A: 

Thanks for answering, I am using ObservableCollection and I can not use two lists because i have various views dynamic views depending on the filter we set, and action taken in one view needs to be reflected in other views...i can implement this one collection for each view, but it will be much messy...

A: 

Anyone...?

+1  A: 

You can just break the binding. In your freeze button handler say:

listView = _list

Which will freeze it at that point. Then in your unfreeze handler set the binding back up:

listView.SetBinding(ListView.ItemsSourceProperty, New Binding("_list"))

I hope this helps.

Bryan Anderson
A: 

It sounds good...but Assigning list ( observablecollection) to Listview gives compilation error...Is there anyother way we can do this.

Bryan's answer should work if you copy the ObservableCollection into a new List and assign it to ListView.ItemsSource.
Robert Macnee
A: 

hmmm we have resolved it, by unsubscrbing data from server for that time and resubscribing again when user clicks unfreeze...