h1

Hello,

I'm using a gridview/listview in order to display a grid of data to the user.

However the potential # of rows can be very very large. So:

1. I don't want to get the entire list.

2. If I can, I would like to avoid (first, prev, next, last) paging scheme.

So I was thinking maybe I could break the list into pages and employ lazy loading. In other words, have a slot of pages (lets say 5 pages), and as the user scrolls, I move the slot of pages and proactively gather rows from the db, keeping a few steps ahead of the user.

I realize that the user may scroll faster than the lazy-loader or may just jump to the end of the list (I'm not sure how to solve those problems yet: one step at a time I guess).

I got 2 of questions for now:

1. Is there an existing mechanism in WPF that would help me do this I know there is a virtualization control that the list box uses, but can I hook up to it and do lazy loading.

2. Has someone done this before Or is there an example that would help me get started

Thanks

Houman



Re: Windows Presentation Foundation (WPF) Smart & Lazy Scrollable List ;-)

Josh Smith

I recently blogged about something similar to your situation: http://www.infusionblogs.com/blogs/jsmith/archive/2006/10/28/917.aspx My blog shows how to throw away the items that are scrolled out of view, and it also has a simplisitic lazy-loading mechanism. You might find that what I examine in that blog entry is relevant to your problem.

HTH






Re: Windows Presentation Foundation (WPF) Smart & Lazy Scrollable List ;-)

Houman b

Thanks Josh, it looks very good. I'm going to go through it.

Houman





Re: Windows Presentation Foundation (WPF) Smart & Lazy Scrollable List ;-)

Houman b

I finally got a chance to come back to this problem.

I'd like to apply data virtualization to listviews.

In order to figure out, what elements are visible in the listview's viewport; I needed to figure out how to manipulate and capture scroll bar events. I checked out a great series on IScrollInfo: http://blogs.msdn.com/bencon/archive/2006/12/09/iscrollinfo-tutorial-part-iv.aspx.

However I don't know how to apply that technique to ListView. Because a ListView has its own scrollViewer and doesn't expose IScrollInfo.

Any ideas on how to manipulate the Extent and viewport size; and capture scroll bar events such as lineUp,lineDown, etc on a ListView

Thanks

Houman





Re: Windows Presentation Foundation (WPF) Smart & Lazy Scrollable List ;-)

Josh Smith

Why not just rely on the Loaded/Unloaded events to know when items are in view The blog post I linked to in this thread uses those events to know when data objects should be brought into memory and released.




Re: Windows Presentation Foundation (WPF) Smart & Lazy Scrollable List ;-)

Houman b

Hi Josh,

I looked at your post when I saw your original posting. It is intresting, but I'm not sure if it can help me in this context.

Just as a refresher, I want to avoid the next/prev paging buttons and rely on the scrolbar for paging.

Here are 2 reasons, as to why I don't think I can rely on Load/Unload (I could be wrong, please correct me):

1. Imagine that my listview needs to manage hunderds of thousounds of items. In this secnario UI virtualization isn't as helpful as data virtualization. What I mean is that I don't want to load 200,000 objects from the db, send it across the wire to the client, only to show 40 of them.

2. If I knew that the client can only see 40 rows in the viewport of my ListView (out of the 200,000 rows), then I could potentially grab 400 rows from the db send it to the client and monitor the scrolbar to update that cache. In that scenario I would need to set the size of the extent and the size of the viewport.

I already have paging with next/prev buttons working, I have a feeling that what I'm chasing here (paging through scrolbar) is way too ambitious:

* There are boundary conditions: what happens if the user just drags the scrolbar from one end to another.

* What happens if the user selects one row then goes to the end of the list press shift and select the last row.

* etc.

I'd really appreciate your input.

Thanks

Houman





Re: Windows Presentation Foundation (WPF) Smart & Lazy Scrollable List ;-)

jk67

Using VisualTreeHelper, locate the ListView's ScrollViewer - write an event handler for the scroll viewer's OnScroll event - in this, at appropriate ratios of ExtentHeight/ScrollableHeight (say 50%), fire a database query asynchronously (using Background Worker pattern) - once the background worker completes, append to the observable collection that binds to the listview. The scroll event can continue to fire whenever the scroll is clicked and satisfies the ratio criteria. While the async query fires, scrolling can carry on without the UI being blocked. Hope this helps.



Re: Windows Presentation Foundation (WPF) Smart & Lazy Scrollable List ;-)

Josh Smith

Houman,

I see what you are saying. My honest opinion is that you shouldn't be showing the user 200,000 items in a ListView. In my experience, users don't like having to hunt through hundreds of items, nevermind hundreds of thousands of them. Perhaps you might want to find a way to filter the list of items in the ListView, so that the number of items becomes more manageable; both for you and your users. Granted, I don't know the context in which you are working and what rationale you have for presenting the user with 200,000 items in a list, but I would seriously consider not showing that many items.