none
Update Listview-Binding to O/R-Mapper EntitySet RRS feed

  • Question

  • I bound an LINQ O/R-Mapper EntitySet to a ListView. Works.

     

    But when I add an item to the EntitySet, the ListView does not show the new item.

    I tried to call refresh for Items and Itemsource to no avail (

    CollectionViewSource.GetDefaultView(MyListView.ItemsSource).Refresh()Wink

     

    Instead of binding I tried to apply the EntitySet to the ItemsSource. Still nothing. Added Refresh() for ItemsSource and Items. Still nothing. (Funny though, in the debugger the ItemsSource does show 1 item after add, while Items still shows 0 items).

     

    So after the Add I reapplied MyListView.ItemsSource = myEntitySet. Still did nothing.

     

    If I use some other IEnumerable, it works, but I need the EntitySet and just can't figure out why it does not work at all.

     

    Maybe an O/R-Mapper/Designer EntitySet is not meant to be used with ListBoxes? But in that case, why does everything but adding a new item work?

     

    *Sigh* I feel stupid.

     

    Sam

     

    Wednesday, September 3, 2008 2:12 PM

Answers

  • The EntitySet I'm binding to is from the O/R-Designer, generated by MSLinqToSQLGenerator.

     

    Therefore there is neither an All Items, nor a .ToList() that could be called. The generated class I'm binding to is an System.Data.Linq.EntitySet.

     

    I just fiddled around some more, I found a workaround to refresh the items by using the following call:

     

    MyListView.ItemsSource = myEntitySet.GetNewBindingList();

     

    Still, it would be much nicer if there is some kind of refresh, or even better, if it would work like the observablecollection.

     

    Sam

     

    Thursday, September 4, 2008 9:31 AM

All replies

  • I assume your entityset is a table and you are adding something like "All items" entry

     

    You might try converting to a list, e.g. using .ToList() at the end, then adding to the list and binding to that instead.

     

    Alternatively, add the "All items" to the ListView.Items before binding and set AppendDataboundItems = true

    Thursday, September 4, 2008 9:07 AM
    Answerer
  • The EntitySet I'm binding to is from the O/R-Designer, generated by MSLinqToSQLGenerator.

     

    Therefore there is neither an All Items, nor a .ToList() that could be called. The generated class I'm binding to is an System.Data.Linq.EntitySet.

     

    I just fiddled around some more, I found a workaround to refresh the items by using the following call:

     

    MyListView.ItemsSource = myEntitySet.GetNewBindingList();

     

    Still, it would be much nicer if there is some kind of refresh, or even better, if it would work like the observablecollection.

     

    Sam

     

    Thursday, September 4, 2008 9:31 AM