Results 1 to 10 of 10

Thread: if list1.selected <> then

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208

    Unhappy very simple listbox thing ...

    How can I check if one item is selected in a list box ???


    [Edited by pro2 on 10-06-2000 at 05:26 PM]

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    If list1.text = "yourtext" then Msgbox "Selected"

    If list1.listindex = 1 then Msgbox "ListIndex " list1index selected
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Guest
    To check a specific item
    Code:
    If List1.Selected(5) = True Then
        'Item 5 is selected
    End If
    To see if any item is selected
    Code:
    For i = 0 To List1.ListCount
        If List1.Selected(i) Then 'There is an item selected
    Next i

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    is it
    For i = 0 To List1.ListCount
    If List1.Selected(i) Then 'There is an item selected
    Next i

    or
    For i = 0 To List1.ListCount -1
    If List1.Selected(i) Then 'There is an item selected
    Next i

    ??
    cause the List count start to 1 and the Index start to 0 ..

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    The listindex is zero based
    so from 0 to list1.listcount -1
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    Ok thank'x a lot..
    its workin..
    but you forgot the
    = True

    in the second exemple Megatron ..

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>


    For i = 0 To List1.ListCount
    If List1.Selected(i) Then 'There is an item selected
    Next i


    You don't need the True for it to work
    However he did forget the list1.lsitcount -1
    and the end if

    But I'm sure you figured that out.

    Code:
    For i = 0 To List1.ListCount - 1
        If List1.Selected(i) Then
           MsgBox "selected " & List1.ListIndex
        'There is an item selected
        End If
        
    Next i
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  8. #8
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362

    Re: <?>

    Originally posted by HeSaidJoe


    However he did forget the list1.lsitcount -1
    and the end if

    But I'm sure you figured that out.
    Actually he didn't leave the End If out... it is not necessary if the Then is
    satified on the same line as the IF.

    Code:
    i = i + 1
    If i = 3 then i = 0  'you do not need an End If
    PictureBox1.Picture = PictureBox2(i).Picture

    [Edited by dsy5 on 10-06-2000 at 06:52 PM]
    Donald Sy - VB (ab)user

  9. #9
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    dsy5: Thank you for the correction:
    What you say it TRUE

    Megatron, my humbles apologies...I added a line to your code without realizing I did.

    Wayne
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  10. #10
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    It should be emphasized that the properties mentioned in HeSaidJoe's original response (Text or ListIndex) are all you need if only one item in the listbox can be selected - i.e., if the MultiSelect property is set to its default of "0 - None". You only need to loop through the items and check the Selected(x) property if you are allowing multi-selection (MultiSelect = Simple or Extended).
    "It's cold gin time again ..."

    Check out my website here.

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