thermacore
thermacore

Reputation: 129

how to load displayed sql data into wpf scrollable list view? large collection (20k+) without running into memory problems?

i have a large collection in a sql database. when i use DataSet, i'm assuming i'm pulling all (and when I say all, i mean 20000+) database entries at once to populate a scrollable WPF list view. when i pull that much data, and more data is added, i'm running out of memory.

i asked a similar question here:program using up all memory from listview sql table, how to populate with only the relevant data? and i need to use it with a list view.

how do i only pull the data i need when the user scrolls? would DataRead work here? i've seen tutorials on DataRead, but they're usually button based, and i need to dynamically read the data based on which direction the user scrolls in the list view.

is there a way to make it update based on, say 30, values, if the user sees 15 of them, then the lag between the server query and returned value wouldn't cause the list view to have any problems as the user scrolls up or down?

Upvotes: 3

Views: 1711

Answers (2)

k.m
k.m

Reputation: 31454

i'm assuming i'm pulling all (and when I say all, i mean 20000+) database entries at once to populate a scrollable WPF list view

Why? Can you imagine anyone analyzing 20000+ elements at once? Do you expect your users to look at 20000+ elements at once? You should have a very good reason to pull entire data set at once. "To display for users" is rarely such reason.

Those kind of problems are usually dealt with in either of two ways:

  1. Pagination. To improve user experience you can always fetch couple extra pages upfront, so that transitioning between pages is seamless.
  2. Virtualization. Most WPF controls have this feature built in (can be easily enabled). Unless you changed your ListView ItemContainer (from VirtualizingStackPanel to something else) or manually disabled virtualization, it should work fine.

On the SQL side, you want to have queries with limit and offset to decide at runtime which part of data set should be fetched.

Upvotes: 1

Moran Moshe
Moran Moshe

Reputation: 114

Please check the next link Data virtualization in codeProject

Upvotes: 1

Related Questions