I have a combobox that is bound to ObservableCollection<Item> in the ViewModel. When a user adds a new item I don’t know if they’ve added an item to the bound collection so I do a refresh. Well this sets the selecteditem to null so I implemented some code to remember the selected item and set it after the Collection is renewed. The problem is the collection doesn’t display the selecteditem.
if (_selectedBrand != null)
{
int selectedBrandID = _selectedBrand.BrandID;
Brands = null;
Brands = new ObservableCollection<Brand>(_dataContext.Brands.ToList());
SelectedBrand = _dataContext.Brands.First<Brand>(b => b.BrandID == selectedBrandID);
}
How can I get the collection to display the corrected item?
Edit: The collection represents a table in the backend DB. The user can open a new window to add items to the DB. Once the window is closed I must refresh the collection to get any new items. Sorry for the confusion of my wording.
Can you not just retrieve the new collection, and then update the existing one adding in the missing values (using the linq extension except?)