Pole vybran²ch polo₧ek v ListBoxu

Postup:
Deklarujte v deklaraΦnφ Φßsti formulß°e:

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 

Private Const LB_GETSELITEMS = &H191

Funkce pro zjiÜt∞nφ poΦtu vybran²ch polo₧ek:

Function GetListBoxSelectRange(lb As ListBox) As Long() 

   Dim selCount As Long 

   ' ZjiÜt∞nφ poΦtu vybran²ch polo₧ek (to samΘ jako vlastnost SelCount) 
   selCount = SendMessage(lb.hwnd, LB_GETSELCOUNT, 0, ByVal 0&) 

   ReDim result(0 To selCount) As Long 
   ' NaΦtenφ vÜech index∙ v jednΘ operaci 
   If selCount > 0 Then 
      SendMessage lb.hwnd, LB_GETSELITEMS, selCount, result(1) 
   End If 

   GetListBoxSelectRange = result() 

End Function

Funkce vracφ pole index∙ vÜech vybran²ch polo₧ek v ListBoxu, prvnφ index zaΦφnß na hodnot∞ pole 1. Funkci pak m∙₧ete pou₧φt nßsledovn∞:
   Dim i As Long 
   Dim indexes() As Long 
   indexes() = GetListBoxSelectRange(List1) 
   For i = 1 To UBound(indexes) 
      Debug.Print "Vybrßno " & indexes(i) 
   Next

Zp∞t

Autor: The Bozena