Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleUse Windows messages to read the choices in a ComboBox
KeywordsComboBox, list choices
CategoriesControls
 
Use the SendMessages API function to send the CB_GETCOUNT, CB_GETLBTEXT, CB_GETLBTEXTLEN messages to the control.
 
Private Sub Command1_Click()
Dim num As Long
Dim i As Integer
Dim txt As String
Dim entry As String
Dim length As Long

    ' See how many entries the ComboBox has.
    num = SendMessage(Combo1.hwnd, CB_GETCOUNT, 0, 0)

    ' Read each entry.
    For i = 0 To num - 1
        ' See how long the entry is.
        length = SendMessage(Combo1.hwnd, CB_GETLBTEXTLEN, _
            i, 0)
        
        ' Make entry big enough.
        entry = Space$(length + 1)

        ' Get the entry.
        length = SendMessage(Combo1.hwnd, CB_GETLBTEXT, i, _
            ByVal entry)
        txt = txt & Left$(entry, length) & vbCrLf
    Next i
    
    MsgBox txt
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated