How can I refresh a ListView using APIs? SendMessage? What arguements? Thank you
Printable View
How can I refresh a ListView using APIs? SendMessage? What arguements? Thank you
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
I ususally just clear and reload the listview control after each add or delete.
What APIs does Visual Basic use when I do something like ListView1.Refresh or is Edgemeal's code it? Thank you
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).