locked
List of 10 000 items. How to load item from database when loading row? RRS feed

  • Question

  • Hello. I have simple code that gets list ofr 10 0000 persons from database:
    using(MyDb db = MyDb.GetDatabase())
    {
    List<Persons> persons = db.Persons.Take(10000).ToList();
    myDataGrid.ItemsSource = persons;
    }
    Loading this list takes a lot of time and even it takes even more time viewing this list in myDataGrid. Setting myDataGrid.EnableRowVirtualization = True helps a little but I was wondering if it is possible that the list contains about 30 items (as much as can fit in the screen) and when I start to scroll down, then new items are loaded in the list from database?
    Tuesday, November 13, 2012 7:27 AM

Answers

  • As for your question, sure you can, but it's not so easy. If you have fixed height items, you know what you're currently showing to screen, you also know the maximum count of items, so you know how big the scrollbar should be.

    There is no easy way. And this wont help you make the list "better viewable". Datagrid is known to handle only 100 items at best.

    DO the loading in background thread and use ObservableCollection with timer(every 20ms) you add ~30 items. See how that works. Otherwise resort to more performance wise datagrids(non wpf)


    C#/C++ | WPF/DirectShow/OpenGL/Winapi/

    • Marked as answer by Sheldon _Xiao Thursday, November 22, 2012 9:16 AM
    Tuesday, November 13, 2012 7:31 AM