Updating Observable Collection
I'm currently working on an app using MVVM that needs to have some data displayed in comboboxes. These are bound to ObservableCollections. The data is stored within a datatable.
I have a number of objects such as, for example, name and location. Each combobox contains either name or location. The list of names have a number next 开发者_JAVA百科to them showing how many people are called that name. The location does similar. Now when the user clicks on a name, the numbers in the location box change to show how many people of that name live in the locations. The name and location objects are completely seperate and know nothing of each other. If the user then clicks on a location, then this would update the name combobox. The raw data is contained in a datatable with name and location column. (There will be approximately 7 comboboxes in the final project, and the dattable will increase accordingly). Is it a case of just querying the datatable again and clearing and replacing the objects in the combobox with the new data?
Sorry for the long winded message.
In case of complete changes of the lists, the ObservableCollection
does little to help you. You might find it easier to have the combo boxes have ItemsSource
to properties on the ViewModel which return an IEnumerable<T>
and call PropertyChanged
when a particular item box is selected (SelectedItem
is set).
精彩评论