Results 1 to 10 of 10

Thread: Selecting Multiple Items in Listbox

  1. #1

    Thread Starter
    Addicted Member Gavin_Mannion's Avatar
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    214

    Talking Selecting Multiple Items in Listbox

    Hi All,

    I have a list box which is populated from an array in the following manner

    VB Code:
    1. For lintCtr = 0 To UBound(ClinicArray, 2)
    2.   '1 for Clinic name
    3.   ClinicList.AddItem ClinicArray(1, lintCtr)
    4.   '0 for Clinic id
    5.   ClinicList.ItemData(lintCtr) = CInt(ClinicArray(0, lintCtr))
    6. Next

    Now what I need to do is when I load my new form that it checks in the database for which clinics someone belongs to and then automatically selects them.

    For example one person is connected to 2 clinics, clinicid 2 and clinicid 9

    These integers match the integers populated in the ItemData options.

    How would I go about using the ClinicList.Selected(???) = TRUE?

    I have the following but it fails if the clinicid is greater than 9??

    VB Code:
    1. Do While Not RS.EOF
    2.      ClinicList.Selected(ClinicList.ItemData(RS("cu_ClinicID"))) = True
    3.      RS.MoveNext
    4. Loop
    Gavin Mannion

    Jackofalltrades.

    "Some people are alive simply because it is against the law to kill them." - Anonymous

    //TODO: Insert smart comment here

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    You probably need to minus 1 to get the index. e.g 9-1 = 8

  3. #3
    Fanatic Member Bonker Gudd's Avatar
    Join Date
    Mar 2000
    Location
    Saturn
    Posts
    748
    Yeah, if there's 9 items in your ListBox then ClinicList.Selected(n) will have n between 0 and 8.

    You'd have to loop through each ClinicList.ItemData otherwise and compare with whats in the RS.

  4. #4

    Thread Starter
    Addicted Member Gavin_Mannion's Avatar
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    214
    Hmm I tried the - 1 in a couple of places but got no joy....

    any other ideas?
    Gavin Mannion

    Jackofalltrades.

    "Some people are alive simply because it is against the law to kill them." - Anonymous

    //TODO: Insert smart comment here

  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    What do you actually want to do?

    Select every item?

    I don't understand what your code is trying to achieve?

  6. #6

    Thread Starter
    Addicted Member Gavin_Mannion's Avatar
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    214
    I have a list of clinics like so..

    ClinicA with ID 4
    ClinicB with ID 8
    ClinicC with ID 15

    Now UserA is linked with ClinicA and ClinicC so when I load his profile onto my form I wish for ClinicA & C to be selected.

    So the 2 ID's I get from my DB are 4 & 15. How do I go about selecting the 2 clinics in the list with this data.

    The list is popualted by Clinic Name and has these ID's as it's ItemData.

    hope that cleared some of that up?
    Gavin Mannion

    Jackofalltrades.

    "Some people are alive simply because it is against the law to kill them." - Anonymous

    //TODO: Insert smart comment here

  7. #7
    Fanatic Member Bonker Gudd's Avatar
    Join Date
    Mar 2000
    Location
    Saturn
    Posts
    748

    Re: Selecting Multiple Items in Listbox

    VB Code:
    1. Do While Not RS.EOF
    2.     For intCount = 0 To ClinicList.ListCount - 1
    3.         If ClinicList.ItemData(intCount) = RS("cu_ClinicID") then
    4.             ClinicList.Selected(intCount) = True
    5.             Exit For
    6.         End IF
    7.     Next
    8.  
    9.     RS.MoveNext
    10. Loop

  8. #8

    Thread Starter
    Addicted Member Gavin_Mannion's Avatar
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    214
    Bonker you the man ...

    Works perfectly....
    Gavin Mannion

    Jackofalltrades.

    "Some people are alive simply because it is against the law to kill them." - Anonymous

    //TODO: Insert smart comment here

  9. #9
    Fanatic Member Bonker Gudd's Avatar
    Join Date
    Mar 2000
    Location
    Saturn
    Posts
    748
    and I didn't even run it

  10. #10
    Lively Member
    Join Date
    Jul 2001
    Posts
    85

    Wink Yeah well I ran it!!!

    and it crashed my PC and the Server, and then the whole network for the entire building went down!!!!!
    and my CPU is on fire!!!
    Know any good techies????

    Just kidding

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