Listbox and lbs_multiplesel

Started by Anonymous, March 16, 2006, 11:40:20 AM

Previous topic - Next topic

Anonymous

I want to be able to get multiple selections from a listbox, and can set it in the properties, but cannot work out how to receive multiple selections in the code. Can anyone help?

TechSupport

There is a couple of ways to do this:

Method #1:

Local I As Long, lRes As Long, txt As String  

lRes = SendMessage( HWND_FORM1_LIST1, %LB_GETSELCOUNT, 0, 0)  

If lRes And (lRes <> %LB_ERR) Then    
  ReDim nSelected(lRes - 1) As Long    
  lRes = SendMessage( HWND_FORM1_LIST1, %LB_GETSELITEMS, lRes, VarPtr(nSelected(0)))  
End If  

For I = 0 To UBound(nSelected)                                  
  ' Loop through the selected items
  MsgBox FF_ListBox_GetText( HWND_FORM1_LIST1, nSelected(I) )
Next



Method #2:

Local nListCount As Long
Local x          As Long

nListCount = FF_ListBox_GetCount( HWND_FORM1_LIST1 )

For x = 0 To nListCount - 1

  If Listbox_GetSel( HWND_FORM1_LIST1, x ) Then
     ' Do what you need to the selected line
     ' e.g. Retrieve the text
     MsgBox FF_ListBox_GetText( HWND_FORM1_LIST1, x )
  End If
 
Next