|
-
Sep 7th, 2000, 03:10 PM
#1
Thread Starter
PowerPoster
1st thread removed.
My situation:
10 comboboxes(arrayed) on a form. On form load, loads all 50 states into the combobox and waits for user selection.
My problem: Once the user picks a state in 1 of the 10, I would like the other 9 to exclude that state in it's selection. I fugured that would be easy enuff, but what if the user picked "Texas" in cboState(5), then I have to make cboState(0-4) then cboState(6-9) exclude "Texas". Can this be done?
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Sep 7th, 2000, 03:46 PM
#2
Thread Starter
PowerPoster
Removing items from combobox
Come on guys. I'm sure some can help me here...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Sep 7th, 2000, 04:25 PM
#3
Try this:
Code:
Private Sub cboState_Change(Index As Integer)
For i = 0 To 10
cboState(i).Text = cboState(Index).Text
Next i
End Sub
Private Sub cboState_Click(Index As Integer)
For i = 0 To 10
cboState(i).Text = cboState(Index).Text
Next i
End Sub
-
Sep 7th, 2000, 05:34 PM
#4
There are a few ways you could do this, here's one:
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const CB_FINDSTRINGEXACT = &H158
Private Sub cboState_Click(Index As Integer)
Dim oCombo As ComboBox
Dim lIndex As Long
Dim sFind As String
'Value to match in other Combo's
'Can;t use index number as it could be in
'a different position for different combo's
sFind = cboState(Index)
'Enumerate each Combo in the Control Array
For Each oCombo In cboState
'Process every combo except the one the user changed
If oCombo.Index <> Index Then
'If the Combo had a previous value, add it back
'to the lists of the other combo's
If Val(cboState(Index).Tag) Then
oCombo.AddItem cboState(Index).List(Val(cboState(Index).Tag))
End If
'Find where the selected value appears in this combo
lIndex = SendMessage(oCombo.hwnd, CB_FINDSTRINGEXACT, 0&, ByVal sFind)
'If found, remove it
If lIndex >= 0 Then oCombo.RemoveItem lIndex
End If
Next
'Remember this value next time, so we can put it back
cboState(Index).Tag = cboState(Index).ListIndex
End Sub
-
Sep 7th, 2000, 06:02 PM
#5
Thread Starter
PowerPoster
Aaron Young:
So, in theory, user selects Texas in one box and Texas is exluded in the other boxes, right? What if, in the same box, the user changes the selection to Arkansas? Would your code then add Texas back to the boxes it was once excluded from?
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Sep 8th, 2000, 04:16 PM
#6
Yes, it would, I'm using the Tag property to Track the Combo's previous value so I can replace it if necessary as you can see in this segment of the code:
Code:
'If the Combo had a previous value, add it back
'to the lists of the other combo's
If Val(cboState(Index).Tag) Then
oCombo.AddItem cboState(Index).List(Val(cboState(Index).Tag))
End If
-
Sep 8th, 2000, 05:30 PM
#7
Thread Starter
PowerPoster
Aaron Young:
Thank your for your response.
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
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
|