CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2001
    Posts
    7

    listbox Refresh?

    how do I keep a listbox from refreshing till I have filled it. If I hide the form. It is much faster.


  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: listbox Refresh?

    If you add items to a listbox using it's Add method it always refreshes the list.

    You can add items using the API which is fatser and in that case you can call LockWindowsUpdate() to prevent the listbox refreshing until it is full. Then call UpdateWindow() to refresh it all.

    The api declarations are:

    Declare Function LockWindowUpdate Lib "user32" Alias "LockWindowUpdate" (byval hwndLock as Long) as Long
    Declare Function UpdateWindow Lib "user32" Alias "UpdateWindow" (byval hwnd as Long) as Long




    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: listbox Refresh?

    This is a code sample from MSDN. Add two List Box controls and a command button on the form. You can select items from the first List Box by Double clicking them. Each selected item will be added to the second List Box control and will be shown when you click the command button.


    private Const WM_SetRedraw = &HB
    private Const LB_ADDSTRING = &H401

    private Declare Function SendMessage Lib "User" (byval hWnd as Integer, byval wMsg as _
    Integer, byval wParam as Integer, lParam as Any) as Integer

    private Declare Function SendMessageByString Lib "User" Alias "PostMessage" (byval hWnd _
    as Integer, byval wMsg as Integer, byval wParam as Integer, byval lParam as _
    string) as Integer

    Sub Form_Load()
    Dim X as Integer
    Dim D as Integer
    Dim S as string
    'Add some dummy data to List1
    for X = 0 to 15
    List1.AddItem "Item #" + Str$(X)
    next X
    End Sub

    Sub Command1_Click()
    'Show updated list box now
    X = SendMessage(List2.hWnd, WM_SetRedraw, 1, 0)
    End Sub

    Sub List1_DblClick()
    'Disable the Repaint event
    X = SendMessage(List2.hWnd, WM_SetRedraw, 0, 0)

    S = List1.List(List1.ListIndex)
    ' Must use SendMessageByString instead of
    ' List2.AddItem S to prevent redrawing
    D = SendMessageByString(List2.hWnd, LB_ADDSTRING, 0, S)
    End Sub







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