-
It sounds simple, but still needs help
I have a combobox with the style of dropdown list. I want some events fired when the user change the list selection.
Common sense leads me to following code
Private sub Combo1_change()
msgbox "selection is changed"
end sub
But it doesn't work. MSDN says:
-------------------
ComboBox — changes the text in the text box portion of the control. Occurs only if the Style property is set to 0 (Dropdown Combo) or 1 (Simple Combo) and the user changes the text or you change the Text property setting through code.
-------------------
Other events such as _lostfocus, _keypress and _click are not working for my purpose.
Any help? thx!
-
If the click event is firing, you can just call your change event code from there.
Code:
Private Sub Combo1_Click
Call Combo1_Change
End Sub
-
Thx
Thanks very much WadeD! It is great!
I have another question here.
For the following code
<code>Private sub combo1_change()
msgbox combo1.text
end sub
private sub combo1_click()
msgbox combo1.text
call combo1_change
end sub</code>
Both msgbox show new Text, anyway to know original text?
Since in my application, some of combo list are not allowed to be changed, I need a way to identify these items and if true, set the text back to original
thanks so much for help
-
Since the only event firing without your intervention is the combo1_click event, I'm guessing that the user can only select values from the combo (not type in a value) and you don't want them to do this in certain instances. If you want to temporarily disable them from selecting a different value, use combo1.enabled = false
If you do want to keep the combo enabled, use this:
Code:
'Declare bAllowChanges as a Public Variable Indicating if Changes Are Allowed Right Now
Private Sub Combo1_Change
If bAllowChanges = True Then
'Store Value
Combo1.Tag = Combo1.ListIndex
Else
'Warn User, Reset Value
Msgbox "This Item May Not Be Changed.", vbOkOnly + vbInformation, "Invalid Entry"
Combo1.ListIndex = Combo1.Tag
End If