How to suppress an event

  • Thread starter Thread starter One Handed Man
  • Start date Start date
Hi,

does anybody know how to suppress an event?
I have a combo box with the following code?

Private Sub cmb_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmb.GotFocus
cmb.DroppedDown = True
End Sub

When the user clicks on the combobox (because this piece of code) it
closes. So I would like to supress this event when the click and dropdown
event fires.
Any Clue?

Regards,

Marco Roberto
 
Well, rather than trying to supress the even, why not supress the action.
Set a class level variable while you are performing whatever it is you are
doing and clear it afterwards. Then the the event in question test that
variable.

OHM
 
Hi,

does anybody know how to suppress an event?
I have a combo box with the following code?

Private Sub cmb_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmb.GotFocus
cmb.DroppedDown = True
End Sub

When the user clicks on the combobox (because this piece of code) it
closes. So I would like to supress this event when the click and dropdown
event fires.
Any Clue?

Regards,

Marco Roberto

You either use a flag... Something like

Private Sub cmb_GotFocus......
Static Done As Boolean

If Not Done Then
' Do your stuff
Done = True
End If
End Sub

Or you loose the handles clause and add the event dynamically and remove
it once processed.

Public Sub Form_Load....
....
AddHandler cmb.GotFocus, AddressOf Me.cmb_GotFocus
End Sub

Private Sub cmb_GotFocus
' Do your stuff
RemoveHandler cmb.GotFocus, AddressOf Me.cmb_GotFocus
End Sub

Then the even will never fire again.
 
Another alternative.

Regards - OHM

Tom said:
You either use a flag... Something like

Private Sub cmb_GotFocus......
Static Done As Boolean

If Not Done Then
' Do your stuff
Done = True
End If
End Sub

Or you loose the handles clause and add the event dynamically and
remove it once processed.

Public Sub Form_Load....
....
AddHandler cmb.GotFocus, AddressOf Me.cmb_GotFocus
End Sub

Private Sub cmb_GotFocus
' Do your stuff
RemoveHandler cmb.GotFocus, AddressOf Me.cmb_GotFocus
End Sub

Then the even will never fire again.
 
Thank OHM, but I need to keep this code because
when the user change the focus to the combo, it
needs to open.
 
It is a good idea!

Tks

One Handed Man said:
Well, rather than trying to supress the even, why not supress the action.
Set a class level variable while you are performing whatever it is you are
doing and clear it afterwards. Then the the event in question test that
variable.

OHM
 
Back
Top