conceptual question re delegates and the firing of events

  • Thread starter Thread starter Bernie Yaeger
  • Start date Start date
B

Bernie Yaeger

I know I'm not getting this clearly: I set up a delegate to execute a
method. I've done this with no problem re validating methods. For example:

I set up the delegate like this:
Delegate Sub callm_dropdown(ByVal sender As Object, ByVal e As
System.EventArgs)

Dim delegd As callm_dropdown

Then I call it, say in a click event of a button:

Dim sender_ As System.Object

Dim e_ As System.EventArgs

delegd = AddressOf ComboBox1_DropDown

delegd.Invoke(sender_, e_)

Now it has the correct signature, so it calls the control's dropdown event.
But I want the delegate to FIRE the dropdown event. Is there a way to use a
delegate not only to execute the dropdown method but rather to FIRE it? In
this case, the combobox does not drop; it only executes the dropdown method.
Is there a different way to get an event to fire in code? That's what I am
really after. Say, click the button and the combobox drops down.

Thanks for any help.

Bernie Yaeger
 
Bernie Yaeger said:
I know I'm not getting this clearly: I set up a delegate to execute a
method. I've done this with no problem re validating methods. For example:

I set up the delegate like this:
Delegate Sub callm_dropdown(ByVal sender As Object, ByVal e As
System.EventArgs)

Dim delegd As callm_dropdown

Then I call it, say in a click event of a button:

Dim sender_ As System.Object

Dim e_ As System.EventArgs

delegd = AddressOf ComboBox1_DropDown

delegd.Invoke(sender_, e_)

Now it has the correct signature, so it calls the control's dropdown event.
But I want the delegate to FIRE the dropdown event. Is there a way to use a
delegate not only to execute the dropdown method but rather to FIRE it? In
this case, the combobox does not drop; it only executes the dropdown method.
Is there a different way to get an event to fire in code? That's what I am
really after. Say, click the button and the combobox drops down.

Correction, it invokes a method that has the same signiture as the dropdown
event. As for firing the event, it is protected and cannot be raised by
anything but the class itself, or an inherited class.
 
Bernie Yaeger said:
I know I'm not getting this clearly: I set up a delegate to execute
a method. I've done this with no problem re validating methods. For
example:

I set up the delegate like this:
Delegate Sub callm_dropdown(ByVal sender As Object, ByVal e As
System.EventArgs)

Dim delegd As callm_dropdown

Then I call it, say in a click event of a button:

Dim sender_ As System.Object

Dim e_ As System.EventArgs

delegd = AddressOf ComboBox1_DropDown

delegd.Invoke(sender_, e_)

Now it has the correct signature, so it calls the control's dropdown
event. But I want the delegate to FIRE the dropdown event. Is there
a way to use a delegate not only to execute the dropdown method but
rather to FIRE it? In this case, the combobox does not drop; it only
executes the dropdown method. Is there a different way to get an
event to fire in code? That's what I am really after. Say, click
the button and the combobox drops down.

By saying "I arrived" you don't drive anywhere.

You can not fire an event. If you want your combo to drop down, set the
DroppedDown property. Afterwards *the combo* will tell *you* that it's been
dropped down by firing the event.
 
Hi CJ,

Well, 'invokes a method that has the same signature as the dropdown' may be
accurate, but in actuality, the dropdown method is triggered - if you have
code in the dropdown method, it executes.

In any case, the firing of the event is what I was after, and if it can only
be raised by an inherited class or the class itself, is there any way to do
this in code such that combobox1's dropdown event will fire?

Thanks for your help.

Bernie
 
See Armin's comment below.
=)

as for my statement, its not your dropdown method is not triggered. Your
handler is because you call it... but its not like raising the event to do
it. It took me awhile to understand delegates, but all it is, as I
understand it, is simply a function pointer.

So you call the same code that you call when you have an event fire,
however, thats just because you pointed to it. The delegate doesn't
determine the result, just the way it gets there. If that makes any sense.

Delegates get tricky, but I will do my best to help out to understand
them... Isn't Spink the self proclaimed "delegate master"? where has he
been? =)
 
Hi Armin,

Thanks for your response.

I do understand your point, but my question is more general than the
specific control I make reference to - simply, I want to know if there's any
way, in code, to fire an event.

Thanks for your help.

Bernie
 
Hi CJ,

Yes, I do understand that a delegate is simply a function pointer. Thanks
again for your help.

Bernie
 
Hey Bernie,

Good to hear, was hoping I didn't offend you in any way. I sometimes
overstate things (Cor will attest to that), but its just to make sure
everyone is communicating the same thing.

Peace.

-CJ
 
Bernie Yaeger said:
I do understand your point, but my question is more general than
the specific control I make reference to - simply, I want to know if
there's any way, in code, to fire an event.

No, not outside the class.
 
Back
Top