Results 1 to 5 of 5

Thread: MultiSelect Listbox(*Resolved*)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Location
    Los Angeles
    Posts
    126

    MultiSelect Listbox(*Resolved*)

    I need to get the actual text of a multiselect textbox and put them all into a string. The items are "ListItem1", "ListItem2" ...
    "ListItem50"
    So that at the end I can basically say "you Chose ListItem1, ListItem5, ListItem28, ListItem40 ...
    I can get only the last item text and not all of them.
    Any help?
    Thanks,
    Michael
    Last edited by IGBP; May 27th, 2003 at 09:54 AM.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    You need to loop through them and say
    VB Code:
    1. If List1.Selected(x) Then
    2. 'Item x is selected
    3. End If
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Location
    Los Angeles
    Posts
    126
    crptcblade
    Can you provide a short example, please :-) I am not having any luck in how I have tried to construct the loop.

  4. #4
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Originally posted by IGBP
    crptcblade
    Can you provide a short example, please :-) I am not having any luck in how I have tried to construct the loop.
    Put a listbox and command button on a form and use this .... this should give you enough idea ....

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4. Dim i As Integer
    5. Dim l_strMonths As String
    6.  
    7.     For i = 0 To List1.ListCount - 1
    8.         If List1.Selected(i) Then
    9.             If Trim(l_strMonths) = "" Then
    10.                 l_strMonths = MonthName(i + 1)
    11.             Else
    12.                 l_strMonths = l_strMonths & ", " & MonthName(i + 1)
    13.             End If
    14.         End If
    15.     Next
    16.     MsgBox "You chose ... " & l_strMonths
    17. End Sub
    18.  
    19. Private Sub Form_Load()
    20. Dim i As Integer
    21.    
    22.     For i = 1 To 12
    23.         List1.AddItem MonthName(i)
    24.     Next
    25.     Command1.Caption = "Show selected"
    26. End Sub

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Location
    Los Angeles
    Posts
    126
    Thanks guys...
    I think I can get it from there :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width