I am using VS2010 – WPF – C#
I have a listview that takes its items from a source using this instruction :
this.listView1.ItemsSource = CollectionViewSource.GetDefaultView(getTicker());
the problem is that every time the source gets updated, my listview doesn’t get updated ??
I know I have to do something with the OnCollectionChanged event but I don’t know how to do it
Please help me with that . . .
I’m not sure why you are using
CollectionViewSource.GetDefaultView(getTicker());Assuming that
getTicker()returns a list of items you can doIf you want to make sure that your listview updates when the source collection changes then you have to use a collection which implements the
INotifyCollectionChangedinterface, for exampleObservableCollectiondoes that. However you have to make sure that your update your collection on the UI thread.Update: Here is how you can use
ObservableCollection:Then you can add/remove items to/from
TickerDataand the UI will update itself automatically becauseObservableCollectionimplementsINotifyCollectionChangedwhich exposes aCollectionChangedevent handler which the listview subscribes to.I think you might want to have a look at some tutorials on WPF.