How to raise a standard event on windows component

  • Thread starter Thread starter Jeremy
  • Start date Start date
J

Jeremy

I have a combobox with a SelectionChangeCommitted event handler, and am
having a problem raising this event.

For example,

raiseEvent mycombobox.SelectionChangeCommitted

gives me an error about not being ended properly. But it won't accept
parameters either. What's the trick here?

Jeremy
 
* "Jeremy said:
I have a combobox with a SelectionChangeCommitted event handler, and am
having a problem raising this event.

For example,

raiseEvent mycombobox.SelectionChangeCommitted

gives me an error about not being ended properly. But it won't accept
parameters either. What's the trick here?

Where do you use this code? Notice that 'RaiseEvent' will only work
inside the class that defines the event. To raise the event from
outside the class, provide a public method that expects the event
arguments in a parameter and raises the event using 'RaiseEvent'.
 
Jeremy,
As the other's suggest only the class itself can raise its events. To allow
derived classes to raise base class events there is a standard Event pattern
you should consider implementing in your classes.

http://msdn.microsoft.com/library/d...s/cpgenref/html/cpconEventUsageGuidelines.asp

Knowing this pattern will allow you to create a custom ComboBox class that
will allow you to raise the event you want.

Something like:

Public Class ComboBoxEx
Inherits ComboBox

Public Sub RaiseSelectionChangeCommitted()
MyBase.OnSelectionChangeCommitted(EventArgs.Empty)
End Sub

End Class

Then instead of using ComboBox, you can use ComboBoxEx on your forms, then
every place you want to raise the SelectionChangeCommitted event, you simply
call the RaiseSelectionChangeCommitted method.

Hope this helps
Jay
 
Back
Top