0

I'm using DispatcherTimer() to call update function to update listview from database where data is updated somewhere else. So, the listview is used as if dashboard.

    private void Update(){
        DateTime d = DateTime.Today;
        items = (from i in DataManager.Entities.signals
                                where i.Date > d
                                orderby i.Id descending
                                select i).Take(MAX_NUM_OF_DISPLAYED);

        this.lvDashboard.ItemsSource = items;          
    }

It works fine until it reaches to certain amount of data. I know I can query last updated data in database and add it to itemssource. I'm trying to make my code simple and clear. Could you give any ideas or suggestions?

---------------- update ---

It updates every 1-2 seconds with 1000 rows of data and the data window keeps moving to the recent data. Some reason the process memory keeps growing. Is DataTable monitors DB updaates?? If the DB is updated some other places, does DB binded DataTable update itself?

icewall
  • 111
  • 6
  • when exactly does it fail(Are you updating your listview quite frequently)??? – MrClan Mar 19 '12 at 11:53
  • Simple and clear often doesn't work well together with fast ;) But as all the people already suggested. Resetting the ItemsSource is propably the worst you can do. Just use the power of databinding, use an ObservableCollection as the ItemsSource, add your data to your list, and let the rest handle by wpf. – dowhilefor Mar 19 '12 at 13:45

2 Answers2

0

It would be more work but if only a subset of the data changes then make items an ObservableCollection and add and remove items. And do NOT rebind.

paparazzo
  • 44,497
  • 23
  • 105
  • 176
0

If you are binding to DataView (underlying DataTable pointing to a database table) the Commit done on the DataTable would refresh the DataView automatically and GUI will show it. But when something other than your code, updates the table and you need to see it updated on the GUI, for this you might want to consider some publisher-subscriber model.

WPF-it
  • 19,625
  • 8
  • 55
  • 71