473,769 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

conceptual question re delegates and the firing of events

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.EventArg s)

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.EventArg s

delegd = AddressOf ComboBox1_DropD own

delegd.Invoke(s ender_, 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


Nov 20 '05 #1
8 1071

"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
news:ON******** ******@TK2MSFTN GP09.phx.gbl...
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.EventArg s)

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.EventArg s

delegd = AddressOf ComboBox1_DropD own

delegd.Invoke(s ender_, 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.
Thanks for any help.

Bernie Yaeger

Nov 20 '05 #2
"Bernie Yaeger" <be*****@cherwe llinc.com> schrieb
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.EventArg s)

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.EventArg s

delegd = AddressOf ComboBox1_DropD own

delegd.Invoke(s ender_, 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.
--
Armin

Nov 20 '05 #3
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

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...

"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
news:ON******** ******@TK2MSFTN GP09.phx.gbl...
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.EventArg s)

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.EventArg s

delegd = AddressOf ComboBox1_DropD own

delegd.Invoke(s ender_, 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.
Thanks for any help.

Bernie Yaeger


Nov 20 '05 #4
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? =)
"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
news:uo******** ******@TK2MSFTN GP09.phx.gbl...
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

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...

"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
news:ON******** ******@TK2MSFTN GP09.phx.gbl...
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.EventArg s)

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.EventArg s

delegd = AddressOf ComboBox1_DropD own

delegd.Invoke(s ender_, 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.
Thanks for any help.

Bernie Yaeger



Nov 20 '05 #5
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

"Armin Zingler" <az*******@free net.de> wrote in message
news:OT******** ******@TK2MSFTN GP09.phx.gbl...
"Bernie Yaeger" <be*****@cherwe llinc.com> schrieb
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.EventArg s)

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.EventArg s

delegd = AddressOf ComboBox1_DropD own

delegd.Invoke(s ender_, 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.
--
Armin

Nov 20 '05 #6
Hi CJ,

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

Bernie

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...
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? =)
"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
news:uo******** ******@TK2MSFTN GP09.phx.gbl...
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

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...

"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
news:ON******** ******@TK2MSFTN GP09.phx.gbl...
> 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.EventArg s)
>
> 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.EventArg s
>
> delegd = AddressOf ComboBox1_DropD own
>
> delegd.Invoke(s ender_, 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.

> Thanks for any help.
>
> Bernie Yaeger
>
>
>
>



Nov 20 '05 #7
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" <be*****@cherwe llinc.com> wrote in message
news:OM******** ******@TK2MSFTN GP10.phx.gbl...
Hi CJ,

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

Bernie

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...
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? =)
"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
news:uo******** ******@TK2MSFTN GP09.phx.gbl...
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

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...
>
> "Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
> news:ON******** ******@TK2MSFTN GP09.phx.gbl...
> > 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.EventArg s)
> >
> > 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.EventArg s
> >
> > delegd = AddressOf ComboBox1_DropD own
> >
> > delegd.Invoke(s ender_, 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.
>
>
>
> > Thanks for any help.
> >
> > Bernie Yaeger
> >
> >
> >
> >
>
>



Nov 20 '05 #8
"Bernie Yaeger" <be*****@cherwe llinc.com> schrieb

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.
--
Armin

Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1590
by: John A. Bailo | last post by:
I'm working through some code that uses events and delegates. Pardon me, but I understand delegates to be a little like function callbacks in c. I coded up a code sample and started playing with it -- but what I don't understand is this. Shouldn't an event behave asynchronously?
8
7399
by: STom | last post by:
I have a C# Winforms app that has 5 Winforms, lets say A through E. A: Data entry. When data is entered here in any field, values are updated on forms C, D, E.(Not B) B: Data entry form. When data is entered here in any field, values are updated on forms C, D, E (not A). I am considering using delegates to fire events from forms A & B. In forms C, D, E I will have functions with the same signature and even the same name that just...
5
8732
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but conceptually speaking : when do I define something as 'struct' and when as 'class' ? for example : if I want to represent a 'Time' thing, containing : - data members : hours, mins, secs
14
1491
by: Mark Allison | last post by:
Hi, I am new to C# and want to create my own events within a console app. However I am struggling mentally with this, and have looked at the MSDN documentation but I am drawing a blank. Is there anywhere on the net that shows a very basic delegate and a very basic event? Some nice simple example code is what I'm looking for with no fluff around it. Thanks!
5
1151
by: JaD | last post by:
I am trying to understand events and delegates which is confusing me. Okay I have a user control that derives from a GroupBox called (MyPanel) I added this: public delegate void Collapsed(); public event Collapsed OnCollapsed; public void CollapseIt() {
4
22886
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on when to use one over another? If anyone could provide any additional info, your comments, best practices, any good articles, specific examples, etc. Thank you
29
1891
by: Brett | last post by:
I'd like to better understand how the following code works. I've posted questions below. namespace Something.Something1 { using System; public delegate void Test1(); public delegate void Test2(ink k);
7
1800
by: RSH | last post by:
I am working through some design patterns, and one recurring theme for me is the need to be able to communicate between objects while promoting encapsulation and loose coupling between them. Based on a couple design patterns I have built a sample app that seems to be a pretty decent model (I think). Is this solution a pretty decent implementation of a process where an x number of objects need to be notified when an event is triggered...
7
3422
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On page 156 I see a WinForms example of timer that uses the "WithEvents" and events. There is another example on page 124 that shows how to use delegates to sort an array. I don't understand the difference between events and delegates. Are they redundant features? How do I decide which to use? ...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9416
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9850
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8862
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7396
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5436
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3551
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.