|
-
Sep 28th, 2000, 10:48 PM
#1
Thread Starter
Frenzied Member
Hi,
I have a combo box with 4 items. I have a Select Case event behind the combobox_click to run code based on the item selected..
However, what I need to do is only run the code if the item selected is different from the already selected item.. For example, the combo box currently shows Item1. If the user clicks the down arrow and selects Item1, I don't want the code to be executed.. But, if the user selects a different item, the code should be run..
Thanks,
Dan
-
Sep 28th, 2000, 11:02 PM
#2
Hyperactive Member
Use a Static variable
In your sub, declare a variable thus:
Code:
Static lastSelected as Integer
Then, check the value of lastSelected before submitting to
the Select Case. At the end of the Sub, set lastSelected
to the value of the currently selected index.
The idea here is that the Static keyword will let your sub
keep the same value for a variable as it did the last time
the sub was executed.
Have fun...
-
Sep 28th, 2000, 11:06 PM
#3
Member
How about this. Use the tag property of the combo box to store the original text in. Then in the click event check to see if the tag is the same as the selected item. I use this often and it works quite well.
Using the tag property you do not need to define an additional variable.
[Edited by d.paulson on 09-29-2000 at 12:22 AM]
-
Sep 28th, 2000, 11:13 PM
#4
Addicted Member
Save the original combobox text to a variable and then
save the newly clicked text to another variable. Then
compare the text in the click event. If the two are the
same then skip the processing, if they are different, then
process the click event.
Example:
Code:
Option Explicit
Dim strOld As String
Private Sub Combo1_Click()
Dim strNew As String
strNew = Combo1.Text
If strNew = strOld Then
Exit Sub
Else
strOld = Combo1.Text
MsgBox "Processing Stuff"
End If
End Sub
Private Sub Form_Load()
Dim intCnt As Integer
'Load the combobox with some stuff for testing
For intCnt = 1 To 10
Combo1.AddItem "Item " & CStr(intCnt)
Next
'Will probably want a "loading info" flag here for
'testing so you don't process a click event on
'form load.
Combo1.ListIndex = 0
strOld = Combo1.Text
End Sub
Hope this helps.
-
Sep 29th, 2000, 12:23 AM
#5
Fanatic Member
Howdy howdy. Here is a quick little fix that I put together, this might work for you (I did a simple project)
Code:
Dim strPrevious As String
Private Sub Combo1_Click()
If Combo1.List(Combo1.ListIndex) = strPrevious Then Exit Sub
Select Case Combo1.ListIndex
Case 0
MsgBox Combo1.List(Combo1.ListIndex)
strPrevious = Combo1.List(Combo1.ListIndex)
Case 1
MsgBox Combo1.List(Combo1.ListIndex)
strPrevious = Combo1.List(Combo1.ListIndex)
Case 2
MsgBox Combo1.List(Combo1.ListIndex)
strPrevious = Combo1.List(Combo1.ListIndex)
Case 3
MsgBox Combo1.List(Combo1.ListIndex)
strPrevious = Combo1.List(Combo1.ListIndex)
End Select
End Sub
Private Sub Form_Load()
Combo1.AddItem "Item1"
Combo1.AddItem "Item2"
Combo1.AddItem "Item3"
Combo1.AddItem "Item4"
Combo1.ListIndex = 0
End Sub
Hope that helps.
-Excalibur
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
|