I want to pull data from a database to display into a ComboBox, and then allow users to select values from that ComboBox and add them into a ListBox (via add/remove buttons). Would I be able to get away with using an ObservableCollections to hold the database values to bind to the ComboBox, since it implements INotifyPropertyChanged (and CollectionChanged)? Sorry if this is a basic question, I starting learning WPF about a month ago.
I’ve read over the article (very well done) by Sacha Barber.
And I’ve looked over the MSDN page on ObservableCollection.
What would be the advantages/disadvantages of using an ObservableCollection vs a List (which I know does not implement INotifyPropertyChanged)?
If the items in your combobox don’t change (i.e. you don’t add/remove/update items), then
Listwill probably be OK for your needs (ObservableCollectionwill be too) if you manually notify that yourListproperty changed when you affect it.If you plan to add/remove or update items in your combobox (without creating a new
MyListobject, i.e. usingthis.MyList.Add(...)), then useObservableCollectionthat is able to notify when the collection is updated (so it can update bindings).