Results 1 to 5 of 5

Thread: Refresh ListView With APIs

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Refresh ListView With APIs

    How can I refresh a ListView using APIs? SendMessage? What arguements? Thank you

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Refresh ListView With APIs

    Not sure what you mean by refresh, but heres some code used to suppress redraw.

    You could try, Redraw ListView1.hWnd, and see if that helps.

    Code:
    Private Const RDW_ERASE       As Long = &H4&
    Private Const RDW_INVALIDATE  As Long = &H1&
    Private Const RDW_ALLCHILDREN As Long = &H80&
    Private Const RDW_UPDATENOW   As Long = &H100&
    Private Const WM_SETREDRAW = &HB
    
    Private Declare Function RedrawWindow Lib "user32.dll" ( _
        ByVal hWnd As Long, ByVal lprcUpdate As Long, _
        ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As Long
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    
    Public Sub SupressRedraw(ByVal hWnd As Long)
        Call SendMessage(hWnd, WM_SETREDRAW, 0, ByVal 0&)
    End Sub
    
    Public Sub Redraw(ByVal hWnd As Long)
        Call SendMessage(hWnd, WM_SETREDRAW, 1, ByVal 0&)
    
        Call RedrawWindow(hWnd, ByVal 0&, 0, RDW_ERASE Or _
                                              RDW_INVALIDATE Or _
                                              RDW_ALLCHILDREN Or _
                                              RDW_UPDATENOW)
    End Sub

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Refresh ListView With APIs

    I ususally just clear and reload the listview control after each add or delete.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Re: Refresh ListView With APIs

    What APIs does Visual Basic use when I do something like ListView1.Refresh or is Edgemeal's code it? Thank you
    Last edited by abazabam; Jun 1st, 2008 at 12:57 PM.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Refresh ListView With APIs

    I doubt if any API's are used at all by VB for ListView1.Refresh, as it already has a direct link with the control - so can just pass a message directly (by calling the .Refresh routine that the control exposes).

    I would expect Edgemeal's Redraw routine to do the same thing, but slightly less efficiently, as the message needs to be passed to Windows first, then back to the control (via any items which are hooking into the controls message queue).

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