Link to home
Start Free TrialLog in
Avatar of Yury Merezhkov
Yury MerezhkovFlag for United States of America

asked on

From ListBox to Array Problem

Hi experts,

I'm getting selected items from listbox and populating an array with them. I want to get all of listbox items if nothing is selected and populate the same array with them. What do I need to add to my code? Thanks.

    For i = 0 To Me.Client_List.ListCount - 1
        If Me.Client_List.Selected(i) Then
            c = c + 1
            ReDim Preserve Clients(1 To c) As Integer
            Clients(c) = Me.Client_List.ItemData(i)
        End If
    Next i
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

   For i = 0 To Me.Client_List.ListCount - 1
        If Me.Client_List.Selected(i) or me.Client_List.SelCount = 0 Then
            c = c + 1
            ReDim Preserve Clients(1 To c) As Integer
            Clients(c) = Me.Client_List.ItemData(i)
        End If
    Next i
Avatar of Yury Merezhkov

ASKER

Nope, method or data member SelCount is not found
I also tried ItemsSelected. Didn't work either.
Well, in my vb6 listbox it works, so either
* you have vb.net
* you are using listview
please specify
actually, im using ms access. it has vb 6.3. and i am using listbox for sure. just checked.
vba?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
otherwise:

For i = 0 To Me.Client_List.ListCount - 1
        If Me.Client_List.Selected(i) Then
            c = c + 1
            ReDim Preserve Clients(1 To c) As Integer
            Clients(c) = Me.Client_List.ItemData(i)
        End If
    Next i

if c = 0 then
  c =  Me.Client_List.ListCount
  ReDim Preserve Clients(1 To c) As Integer
  For i = 0 To Me.Client_List.ListCount - 1
    Clients(i+1) = Me.Client_List.ItemData(i)
  Next i
End if