0

The question is a simple one and many of you would already know that Listview is much slower even if it is hidden. There are some suggestions like:

  1. Loading partial data and then load on scrolling, though by default there is no scroll event
  2. Load partial data and then provide button to load more (say 50) records
  3. Load partial data, show the screen and then use timer to load remaining data

What are other suggestions?

How does LockWindowUpdate work? Is it equal to ListView.Visible = False? Can two or more Listviews be locked using this API?

Edit

HyperList looks great but its use is complicated, can some one please simplify it or explain what is going on at caller's end i.e. how to fill the array.

4
  • I think that this is technically a debate type question and doesn't really fit in the format of SO, but I've tried to answer anyway... Commented Apr 25, 2013 at 13:33
  • 1
    @Westie I think the increase in speed can be proved by code snippet, then it wont be a debate but a concrete programming question Commented Apr 25, 2013 at 13:39
  • Also look at the control's virtual mode. I'm not sure this is exposed in the VB6 wrappers though. Commented Apr 25, 2013 at 13:44
  • 1
    Never use LockWindowUpdate() for this issue. It's global and will unlock anything that's using it for the real purpose. Commented Sep 11, 2014 at 9:09

3 Answers 3

1

The most obvious solution here is a cross between all of those you mentioned; basically paging. Load a set number and then allow the user to page backward and forward using a numbered page sequence above or below the ListView control.

To speed up further don't use an active RecordSet; instead, load the data into an array and directly drop the information into the control. Use an alternative form if you want to edit the information rather than editing in the ListView control.

Alternatively you could just create your own ListView equivalent and write the objects directly onto the form yourself using your own format.

I think that if you have to use something like LockWindowUpdate then you're going down the wrong path. You should just be able to use the appropriate property of the control to prevent user interference.

-- EDIT --

The idea is to read the data into an array in memory and then loop through it and populate your ListView in a similar way to this:

Private Function TestInsertListView() As Long
    Dim i As Long
    Dim j As Long
    Dim lT As Long
    Dim itmX As ListItem
    lT = timeGetTime

    ' Add first row
    With lvwTest
        i = 1
        Set itmX = .ListItems.Add(, , "Row" & i & ";Col 1")
        For j = 2 To mcCOLS
           itmX.SubItems(j - 1) = "Row" & i & ";Col" & j - 1
        Next

        For i = 2 To m_iRows
           Set itmX = .ListItems.Add(i, , "Row" & i & ";Col 1")
           For j = 2 To mcCOLS
              itmX.SubItems(j - 1) = "Row" & i & ";Col" & j - 1
           Next
        Next
     End With
     TestInsertListView = timeGetTime - lT

End Function

(I found the above example here.)

Obviously you'd need to modify the above to include the reading of the data but that should be pretty straightforward. This link gives a demo of the ADO GetRows method which allows you to read the data.

Sign up to request clarification or add additional context in comments.

2 Comments

"directly drop the information into the control", what do you mean?
You'll have to forgive me here, my VB6 is reaaally rusty! I'm just updating my post above...
1

For suggestion #1 - You could either superempose your only vertical scroll bar on top of the list view control, or subclass the ListView control.

Alternatively, you could use the ItemClick() event (clicking items near the bottom of the list) to determine whether more lines need to be loaded.

Don't use LockWindowUpdate - that is meant to be used for processes which need to draw into windows belonging to other processes when do drag-drop. Google OldNewThing LockWindowUpdate for articles explaining how it works and why using this is a bad idea. It isn't equal to ListView.Visible = False. You can only use one window at a time with this API call.

Use the following SendMessage calls to disable and enable updating.

Private Declare Function SendMessage Lib "User32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_SETREDRAW  As Long = &HB
Private Const SR_ON         As Long = 1
Private Const SR_OFF        As Long = 0

SendMessage ListView.hWnd, WM_SETREDRAW, SR_OFF, 0&
SendMessage ListView.hWnd, WM_SETREDRAW, SR_ON, 0&

Comments

0

Make sure sorting is disabled while it is loading.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.