Cant insert a object into a silverlight databound combo box

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2010-05-04T15:56:04Z Indexed on 2010/05/04 16:58 UTC
Read the original article Hit count: 218

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about c#