Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a datagrid bound to a CollectionViewSource:

XML
    <Window.Resources>
        <CollectionViewSource x:Key="vs"></CollectionViewSource>
    </Window.Resources>


<DataGrid x:Name="dg" ItemsSource="{Binding Source={StaticResource vs}}" AutoGenerateColumns="true"/>



I populate the CollectionViewSource.Source using entity framework:

VB
Private vsAs CollectionViewSource
vs = CType(FindResource("vs"), CollectionViewSource)

dim db as new dbcontext
vs.Source = db.SomeEntities.ToList



I want this data to refresh itself from the database every so often, at the moment I have it on a timer like so:

VB
    'invoker is used so objects of a different thread can be accessed
    Me.Dispatcher.Invoke(Sub()
                           dim db as new dbcontext
                           vs.Source = db.SomeEntities.ToList
                         End Sub)


End Sub


However this causes any sorting from the datagrid, along with any selected items to be lost, it also causes a noticable delay on screen.

What is the correct way to update a collectionviewsource from a database using entity framework?

Thanks
Posted
Updated 25-Feb-15 3:10am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900