Click to See Complete Forum and Search --> : How to scroll a listview programmatically


mskvarenina
January 23rd, 2000, 06:46 PM
I need to scroll a listview programmatically. Basically I have a very large database and I want to load the first 25 records and provide the user with a "next 25" button. When they press this button I will "add" another 25 items to the listview but I need to "scroll" the listbox up one page so records 26-50 show.

As an alternative, I'd also appreciate suggestions on how to handle this large database situation. Basically I have about 1 million names in a database. I am giving the user a search option that begins reading the database at the first name that matches, then I load the listview with 25 records. Perhaps there's another control or method out there to accomplish this. I obviously can't load the entire listview at once.

Chris Eastwood
January 24th, 2000, 09:47 AM
You can scroll the listview dynamically by sending the LVM_SCROLL message to the ListView (with the sendmessage API).

As you are thinking of loading 1 million records into the listview though, I'd suggest a bit of a rethink to how you are going to accomplish this. The ListView has a 'virtual' mode where items are only added to it when required (ie. scrolled) - unfortunately for us VB programmers, we don't get access to that style of ListView as the style flag needs to be set once the ListView is being created.

Theres some excellent 'hard-core' code at http://nickerson.org that shows how to create a 'virtual' listview - but it is quite heavy going.


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb

Lothar Haensler
January 24th, 2000, 10:24 AM
how about calling the EnsureVisible function of the ListItem object.
If you do that, the chosen Item will be made visible. That includes scrolling if necessary.

mskvarenina
January 24th, 2000, 09:29 PM
>>As you are thinking of loading 1 million records into the listview though

Actually the situation I have is this: I have a database of over 1 million records, sorted by name. I am presenting the user with a search textbox and when they enter something, say "AB" for example, I want to fill the listview with all the "AB"s. But since there could be hundreds or thousands of "AB"s, I don't want to fill the listview all at once but rather one page at a time. I have a "Next 25" button on the form which when pressed, gets the next 25 records. It was here I was having the problem scrolling the listview. Someone suggested using the EnsureVisible method which does scroll the listview to the next "page". Now my question is, has anyone else encountered situations like this where you have many many records and wanted to display a subset at a time between fetches? And if how, what 'search' and results displays did you use?

Chris Eastwood
January 25th, 2000, 02:58 AM
I did work with something (a *long* time ago) that implemented this with threads (and was written in C) - VB doesn't offer you that much flexibility with threads, although I understand that there are asynchronous methods available to the ADO recordset objects (unfortunately I've never used them this way - Lothar Haensler's the man for this one)


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb