dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB6
Expertise: Intermediate
Nov 4, 2000

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


GetListBoxSelectRange - Retrieve the index of all the selected items in a ListBox

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
Const LB_GETSELITEMS = &H191

' Return an array with the indexes of all the selected items in a ListBox 
' control
'
' the array is zero-based, but the significant values 
' are from index 1 onward
' This is how you can use this routine
'   Dim i As Long
'   Dim indexes() As Long
'   indexes() = GetListBoxSelectRange(List1)
'   For i = 1 To UBound(indexes)
'       Debug.Print "Selected " & indexes(i)
'   Next

Function GetListBoxSelectRange(lb As ListBox) As Long()
    Dim selCount As Long

    ' Retrieve the number of selected items (same as SelCount property)
    selCount = SendMessage(lb.hwnd, LB_GETSELCOUNT, 0, ByVal 0&)
    ' prepare the result array
    ReDim result(0 To selCount) As Long

    ' read all the indexes in one operation
    If selCount > 0 Then 
        SendMessage lb.hwnd, LB_GETSELITEMS, selCount, result(1)
    End If
    ' return the array
    GetListBoxSelectRange = result()
End Function
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date