CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 1999
    Location
    Texas
    Posts
    96

    ListView updating

    I have a rather large recordset that I display in a listview. How do you turn off the updating (or redraw) property for the listview via API?

    Thanks


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: ListView updating

    You can use the SendMessage API with the WM_SETREDRAW message on most controls :

    Here's an example I use to clear down a treeview with 100's of nodes - it's far quicker than the standard nodes.clear method, and it uses the WM_SETREDRAW message to make it even faster :



    '
    ' Constants / Declarations - Change public / private as required
    '
    public Const TV_FIRST as Long = &H1100
    public Const TVM_GETNEXTITEM as Long = (TV_FIRST + 10)
    public Const TVM_DELETEITEM as Long = (TV_FIRST + 1)
    public Const TVGN_ROOT as Long = &H0
    public Const WM_SETREDRAW as Long = &HB
    '
    public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _
    (byval hwnd as Long, byval msg as Long, byval wParam as Long, _
    byval lParam as Long) as Long
    '
    ' Very fast Clearing of treeview control - Place this where required
    '
    private Sub ClearTreeView(byval tvHwnd as Long)
    '
    Dim lNodeHandle as Long
    '
    ' Turn off redrawing on the Treeview for more speed improvements
    '
    SendMessageLong tvHwnd, WM_SETREDRAW, false, 0
    '
    Do
    lNodeHandle = SendMessageLong (tvHwnd, TVM_GETNEXTITEM, TVGN_ROOT, 0)
    If lNodeHandle > 0 then
    SendMessageLong tvHwnd, TVM_DELETEITEM, 0, lNodeHandle
    else
    Exit Do
    End If
    Loop
    '
    ' Turn Drawing back on ...
    '
    SendMessageLong tvHwnd, WM_SETREDRAW, true, 0
    End Sub




    Chris Eastwood

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

  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: ListView updating

    some people say that LockWindowUpdate is even faster and easier to call.


    private Declare Function LockWindowUpdate Lib "user32" Alias "LockWindowUpdate" (byval hwndLock as Long) as Long
    LockWindowUpdate yourcontrol.hWnd
    ' if you want to update again...
    LockWindowUpdate 0





  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: ListView updating

    I agree - most people say use LockWindowUpdate, but when ever I've tried to use it (when 'unlocking') - the whole desktop tends to flicker and get redrawn - (which looks really ugly). I tend to use the WM_SETREDRAW method now in a wrapped routine just like LockWindowUpdate.

    Any ideas on how to get rid of the flickering.... ?


    Chris Eastwood

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

  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: ListView updating

    I have just tried it and couldn't see any flickering or desktop redraw operation.
    I use NT 4 and VB 6.


  6. #6
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: ListView updating

    I've found that it's one of those 'sometimes it does/doesn't' problems. I've had it working fine before on NT4 with VB5/6 and yet the same code on a different machine would do the 'flicker'. It tend's more noticable on a Win98 machine.

    I'm wondering if it's the value placed into LockWindowUpdate to release the 'lock' - I usually call it as :

    LockWindowUpdate 0&

    - But surely this is going to refer to the desktop window ? (Although that doesn't explain the inconsistancies between machines/OS).



    Chris Eastwood

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

  7. #7
    Join Date
    May 1999
    Posts
    3,332

    Re: ListView updating

    >LockWindowUpdate 0&
    >
    >- But surely this is going to refer to the >desktop window ?

    I tend to disagree. Since only ONE window can be locked at a time, IMHO passing 0 to Lockwindowupdate simply means: unlock the window that was locked most recently. Redrawing the desktop in that case simply doesn't make sense to me.
    I haven't had the chance to test that stuff on different machines or OSs, yet.


  8. #8
    Join Date
    Dec 1999
    Location
    Texas
    Posts
    96

    Re: ListView updating

    Thanks guys..both ways seem to do pretty well. Thanks a bunch!!!


  9. #9
    Join Date
    Sep 1999
    Posts
    202

    Re: ListView updating

    >both ways seem to do pretty well.
    Last time I checked this didn't work. ListView was ignoring messages. Are you sure you tested it?


  10. #10
    Join Date
    Dec 1999
    Location
    Texas
    Posts
    96

    Re: ListView updating

    I don't know. I used Spy++ to display messages for the ListView, and when my code ran it said that it was receiving the WM_SETREDRAW messages, but that doesn't mean it actually did anything. Plus, it still flickered a little bit, but that might be because I am resizing the columnheaders after displaying the data.


  11. #11
    Join Date
    Sep 1999
    Posts
    202

    Re: ListView updating

    You should send message to parent form:

    'Declarations
    private Declare Function SendMessage Lib "user32" Alias _
    "SendMessageA" (byval hWnd as Long, byval wMsg as Long, _
    byval wParam as Long, lParam as Long) as Long
    private Const WM_SETREDRAW = &HB
    private Const REDRAWOFF as Long = 0
    private Const REDRAWON as Long = 1

    'Use this in your procedure:
    ' disable repainting
    Call SendMessage(hWnd, WM_SETREDRAW, REDRAWOFF, 0&)
    ' now modify your listview
    ...
    ' enable repainting
    Call SendMessage(hWnd, WM_SETREDRAW, REDRAWON, 0&)



    --------------------------------------
    After setting redrawon, you can use:
    1. ListView.Refresh
    2. Nothing, since next line will do refresh (e.g. setting Sorted property)
    3. best ***
    I am using sometimes:
    private Declare Sub InvalidateRect Lib "user32" _
    (byval hWnd as Long, byval t as Long, byval bErase as Long)
    Call InvalidateRect(Listview1.hWnd, 0&, 0&)
    ' and my forms.ClipControls is set to false





  12. #12
    Join Date
    Sep 1999
    Posts
    202

    Re: ListView updating

    >passing 0 to Lockwindowupdate simply means: unlock the window that was locked most recently
    There are 2 cases (tested on Win95):


    '1. desktop will be repainted
    ' disable repainting
    LockWindowUpdate hwnd
    ' resize our form
    Move Left, Top, Width + 30, Height + 30
    ' do some processing (e.g. dinamically add some controls)
    '
    ' this will refresh DESKTOP
    LockWindowUpdate 0

    '2. only form
    ' resize form before LockWindowUpdate call
    Move Left, Top, Width + 30, Height + 30
    Refresh
    ' disable repainting
    LockWindowUpdate hwnd
    ' do some processing (e.g. dinamically add some controls)
    '
    ' this will refresh only current form
    LockWindowUpdate 0





  13. #13
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: ListView updating

    Thanks Bruno - I'll take a look and see if I'm doing something similar (I expect so)


    Chris Eastwood

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

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