|
-
Oct 17th, 2001, 06:37 AM
#1
Thread Starter
Addicted Member
Selecting Multiple Items in Listbox
Hi All,
I have a list box which is populated from an array in the following manner
VB Code:
For lintCtr = 0 To UBound(ClinicArray, 2)
'1 for Clinic name
ClinicList.AddItem ClinicArray(1, lintCtr)
'0 for Clinic id
ClinicList.ItemData(lintCtr) = CInt(ClinicArray(0, lintCtr))
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:
Do While Not RS.EOF
ClinicList.Selected(ClinicList.ItemData(RS("cu_ClinicID"))) = True
RS.MoveNext
Loop
-
Oct 17th, 2001, 06:50 AM
#2
PowerPoster
You probably need to minus 1 to get the index. e.g 9-1 = 8
-
Oct 17th, 2001, 06:54 AM
#3
Fanatic Member
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.
-
Oct 17th, 2001, 06:55 AM
#4
Thread Starter
Addicted Member
Hmm I tried the - 1 in a couple of places but got no joy....
any other ideas?
-
Oct 17th, 2001, 07:01 AM
#5
Conquistador
What do you actually want to do?
Select every item?
I don't understand what your code is trying to achieve?
-
Oct 17th, 2001, 07:04 AM
#6
Thread Starter
Addicted Member
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?
-
Oct 17th, 2001, 07:16 AM
#7
Fanatic Member
Re: Selecting Multiple Items in Listbox
VB Code:
Do While Not RS.EOF
For intCount = 0 To ClinicList.ListCount - 1
If ClinicList.ItemData(intCount) = RS("cu_ClinicID") then
ClinicList.Selected(intCount) = True
Exit For
End IF
Next
RS.MoveNext
Loop
-
Oct 17th, 2001, 08:40 AM
#8
Thread Starter
Addicted Member
Bonker you the man ...
Works perfectly....
-
Oct 17th, 2001, 08:41 AM
#9
Fanatic Member
and I didn't even run it
-
Oct 17th, 2001, 09:34 AM
#10
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|