Cant insert a object into a silverlight databound combo box
- by Steve
Hi
Until recently I had a combo box that was bound to a Linq queried IEnumerable of a DataService.Obj type in the bind method, and all worked fine
private IEnumerable<DataService.Obj> _GeneralList;
private IEnumerable<DataService.Obj> _QueriedList;
private void Bind()
{
_GeneralList = SharedLists.GeneralList;
_QueriedList = _GeneralList.Where(q =>q.ID >1000);
cmbobox.ItemsSource = _QueriedList;
}
Then I had to change the method to insert a new obj and set that object as the default obj and now I get a "System.NullReferenceException: Object reference not set to an instance of an object" exception. I know this has to do with inserting into a linq queried ienumerable but I cant fix it. Any help will be gratefully received.
private IEnumerable<DataService.Obj> _GeneralList;
private IEnumerable<DataService.Obj> _QueriedList;
private void Bind()
{
_GeneralList = SharedLists.GeneralList;
_QueriedList = _GeneralList.Where(q =>q.ID >1000);
cmbobox.ItemsSource = _QueriedList;
DataService.Obj info = new DataService.Obj();
info.ID = "0";
(cmbobox.ItemsSource as ObservableCollection<DataService.Obj>).Insert(0,info);
cmbobox.SelectedIndex = 0;
}
Thanks in advance