CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 1999
    Location
    MLA, PHIL
    Posts
    11

    OPtimize speed in transferring data to a listview

    Is there a way to speed up the transfer the records from a recordset to a list view object?


  2. #2
    Join Date
    Aug 1999
    Posts
    10

    Re: OPtimize speed in transferring data to a listview

    You can use LockWindowUpdate API to stop any drawings in that ListView that will definetely will speed up the loading process. Here is an example:


    private Declare Function LockWindowUpdate Lib "user32" (byval hwndLock as Long) as Long

    private Sub Command1_Click()
    Dim rs as new ADODB.Recordset
    Dim xItem as ListItem

    'I'm assuming that you already have recordset object opened
    'with the appropriate records

    LockWindowUpdate ListView1.hWnd

    Do Until rs.EOF
    set xItem = ListView1.ListItems.Add(, , rs("MyField"))
    rs.MoveNext
    Loop
    'Unlock ListView
    LockWindowUpdate 0
    End Sub





    Serge
    Programmer Analyst
    [email protected]

  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: OPtimize speed in transferring data to a listview

    LockWindowUpdate sometimes gives a flicker on the Desktop ( 0n WIn95), when released. (ie called with NULL )!. so check it out..

    There are a couple of things you could try.
    If you have set the Sorted Property to TRUE, then each time you add a item, it tries to find out the correct place it fits in the list. So, if you are going to add a lot of records in one go, it would increase speed by first set the sorted property to false, a
    dd all recs in one go, and then set it to true . (the list will comeout correct anyway)

    II. You can try some kind of "Background" processing. Add few records, then add more with occassionally giving up control with DOEvents. set up visual indications that you are doing so. This type of programing requires that you do it correclty. when the process is still on, you will set a flag, and every where you wil check for that flag to be on before proceesing.

    A little out of place here, but i am giving some code i have at hand, which does this kind of a thing. Process a big file ( >5MB on most occasions) for Jpeg markers, and fill a list box with hits and with set of bytes after the marker:

    ...
    nBaM = CInt(txtBytesToDisp.Text) ' no. of bytes after marker.
    nl = UBound(m_cFileBuf) ' array size = file length
    lstJpgMarker.Clear

    nl = IIf(twobytes, nl - 1, nl) ' for two byte processing case
    Screen.MousePointer = vbHourglass
    for ii = 0 to nl - 1
    If twobytes = false then
    addit = IIf(m_cFileBuf(ii) = cMarker(0), true, false)
    else
    addit = IIf((m_cFileBuf(ii) = cMarker(0)) And _
    (m_cFileBuf(ii + 1) = cMarker(1)), true, false)
    End If
    If addit then
    lststr = vbNullString
    nBaM = IIf(ii + nBaM > nl - 1, nl - 1 - ii, nBaM)
    for jj = ii to ii + nBaM
    lststr = lststr & " " & Hex$(m_cFileBuf(jj)) & " "
    next jj
    lstJpgMarker.AddItem txtJpgMarker.Text & "@" & Str(ii) & "," & lststr

    lblNMarkers.Caption = Str(ii) & "/" & Str(nl - 1)

    If lstJpgMarker.NewIndex >= 30 then
    Screen.MousePointer = vbArrowHourglass
    If lstJpgMarker.NewIndex Mod 10 = 0 then
    DoEvents
    End If
    else
    DoEvents
    If bstopfill then Exit for
    End If
    End If

    next ii
    lblNMarkers.Caption = Str(lstJpgMarker.ListCount)
    Screen.MousePointer = vbDefault
    Exit Sub
    ...



    More to point: check the bold section. First i add 30 items w/o much ado, then change the cursor to Arror + Hourglass, to indicate that things are going on in the bg ( which also would be evident by scroll bar flicker and decreasing Scroll-bar tab, anyway)
    While things are being added you can scroll the list and it has "stop" support too.

    This section is not 100% fool-proof ( if i close the form, while the proc. is On the program will throw-up!)


    RK

  4. #4
    Join Date
    Dec 1999
    Location
    MLA, PHIL
    Posts
    11

    Re: OPtimize speed in transferring data to a listview

    Thanks I'll try It


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured