DuplicateListBox – Fast copy of the contents of a ListBox control

DuplicateListBox – Fast copy of the contents of a ListBox control

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _    hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _    lParam As Any) As LongPrivate Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) _    As Long   Const LB_RESETCONTENT = &H184Const LB_GETCOUNT = &H18BConst LB_GETTEXT = &H189Const LB_ADDSTRING = &H180Const LB_GETITEMDATA = &H199Const LB_SETITEMDATA = &H19A' Duplicate the contents of a ListBox control to another ListBox control'' Pass False to the last argument to append contents' (the target control isn't cleared before adding elements)'' uses API functions for the fastest codeSub DuplicateListBox(Source As ListBox, Target As ListBox, _    Optional AppendMode As Boolean)    Dim index As Long    Dim itmData As Long    Dim numItems As Long    Dim sItemText As String        ' prepare the receiving buffer    sItemText = Space$(512)        ' temporarily prevent updating    LockWindowUpdate Target.hWnd        ' reset target contents, if not in append mode    If Not AppendMode Then        SendMessage Target.hWnd, LB_RESETCONTENT, 0, ByVal 0&    End If    ' get the number of items in the source list    numItems = SendMessage(Source.hWnd, LB_GETCOUNT, 0&, ByVal 0&)        For index = 0 To numItems - 1        ' get the item text        SendMessage Source.hWnd, LB_GETTEXT, index, ByVal sItemText        ' get the item data        itmData = SendMessage(Source.hWnd, LB_GETITEMDATA, index, ByVal 0&)        ' add the item text to the target list        SendMessage Target.hWnd, LB_ADDSTRING, 0&, ByVal sItemText        ' add the item data to the target list        SendMessage Target.hWnd, LB_SETITEMDATA, index, ByVal itmData    Next        ' allow redrawing    LockWindowUpdate 0    End Sub

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several