Combobox events

k3n51mm

Active member
Joined
Mar 7, 2007
Messages
40
Programming Experience
3-5
I have a dialog form that has 4-5 combobox controls on it. Selecting something in any of the comboboxes affects the other ones.

Is there any way to highlight an item in a combobox without firing the SelectedIndexChanged event?

Or failing that, is there any way to control what happens when a combobox is programmatically selected vs. when the user manually selects an item?

Someone suggested using RemoveHandler and Addhandler, but that smells like a kludge. Any other ideas, or is this the right way to approach it?
 
what I'd probably do is have the function that is selecting it set a variable, like "manual = false"

then in the event code..
if manual then do normal code..
else manual = true
 
Thanks for the reply. How would I do that? I wasn't sure of how I could alter the default events for each combobox created by the IDE, for example:

VB.NET:
Private Sub cbOne_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbOne.SelectedIndexChanged
   'do something here
End Sub

Basically I thought this was all I had to work with, and I wasn't sure where I could add variables or anything, unless they were declared at form level and set during this handler's execution.
 
yes that's what I'm saying

at form level declare boolean manual as false
in the code that manually changing the index, set manual to true
in the selectedindexchanged code you would have something like
if manual then
do normal code
else manual = true

this way when it is programmatically selected it will only change the value and not execute the other code, and when it is selected by the user it will execute the other code
 
Or failing that, is there any way to control what happens when a combobox is programmatically selected vs. when the user manually selects an item?

I have a const string of:


Private Const PROGRAMMATICALLY_CHANGED As String = "changed programmatically"

And whatever combo I am going to change, i set its tag to this:

myCombo.Tag = CHANGED_PROGRAMMATICALLY
myCOmbo.SelectedInedex = 1

then in the handler:

If myCombo.Tag Is CHANGED_PROGRAMMATICALLY Then 'fast reference comparison
'do whatever, remember to unset the Tag first! (set it to nothing)
EndIf



Any other ideas, or is this the right way to approach it?
It works, I just never liked the idea from the point of view that you might forget to re-set it or an exception might cause it to not be added again, and thus it stops working?
 
Sure, I understand. I've never been a fan of the Tag, myself. Seems like it means 'put kludge here'. Thanks for the reply.
 
Back
Top