RobertPitt
RobertPitt

Reputation: 57268

Pagination with ListView

I'm looking for a good technique on paging List Views

Currently I'm building a Active Directory (LDAP) Manager for a company I Work for, the company has over 12K Employees across the board and we need to be able to navigate through these with ease

The two types of pagination I'm considering are:

And the other way which I would prefer to do is:

I'm stuck for ways to do this; has anyone got any good examples or resources?

The data is coming is coming in with 1 main request and stored in memory, soon to be stored in a cached XML file to free the memory, so if reading from that would be faster then that's OK.

I'm using .NET Framework 4.0 and bound to WinForms.

Upvotes: 0

Views: 3454

Answers (2)

KeithS
KeithS

Reputation: 71573

I dunno about tabs, but you could certainly set up a row of Buttons or LinkButtons for A-Z. Tabs are used to organize controls into pages more than data; using tabs would require you to have a ListView on each TabPage.

I would create a lookup UserControl, especially if this functionality will be used in several places. For the layout, all you do is create the UserControl, and drop in your ListView and any navigation controls you want as Buttons, LinkButtons, whatever. You may consider doing this dynamically using a FlowLayoutPanel or similar.

For the codebehind, you need to be able to get your results in pages. The go-to way is with Linq:

var onePage = userDataSource.Skip((pageNumber-1)*perPage).Take(perPage);

Now, your navigation controls manipulate pageNumber and tell the ListView to rebind itself to the new page's data using the above Linq.

For quick access by first character, that's again easy to do in Linq. Instead of skipping X rows until you're in the Cs, just filter out all rows that don't begin with C:

var startswithC = userDataSource
    .Where(x=>x.StringID.StartsWith('C'))
    .Skip((pageNumber-1)*perPage).Take(perPage);

If you know the data source returns ordered results, it is possible to use SkipUntil() to find the Cs, but you'll iterate through a lot of records, and a lot of Linq providers can translate Skip and Take but not SkipWhile, SkipUntil, etc.

Upvotes: 0

dexter
dexter

Reputation: 7203

You'd want to ask for paged data at your LDAP layer of your applicaiton, The gui will just display the page asking for what page number you want to show. Now as far as LDAP, I believe the DirectorySearcher class of System.DirectoryServices has capabilities for pagination:

http://msdn.microsoft.com/en-us/library/system.directoryservices.directorysearcher(VS.80).aspx

Upvotes: 1

Related Questions