473,320 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Events

Can events be used to notify an object that something has happened and it
needs to take some action?

Most of the documentation on events makes them sound like they work the
other way around, that is, an object raises an event to inform other objects
that something happened. I need the ability for many objects to notify a
single object that some event has occurred. e.g. similar to LostFocus.

In C++, I would have used SendMessage() to inform the object that it needs
to take some action but I can't find anything in C# to accomplish the same
thing.

Thanks,
Tom
Nov 15 '05 #1
3 4112
Well, the object you want notified by the other objects could have a public
Notify() method. You could implement it asynchronously, if you need it to
return immediately. Notify() could also take a parameter of this, indicating
which caller called it...
"Tom Bean" <tb***@t-a-c.com> wrote in message
news:#v**************@TK2MSFTNGP12.phx.gbl...
Can events be used to notify an object that something has happened and it
needs to take some action?

Most of the documentation on events makes them sound like they work the
other way around, that is, an object raises an event to inform other objects that something happened. I need the ability for many objects to notify a
single object that some event has occurred. e.g. similar to LostFocus.

In C++, I would have used SendMessage() to inform the object that it needs
to take some action but I can't find anything in C# to accomplish the same
thing.

Thanks,
Tom

Nov 15 '05 #2
If the event you need isn't already provided by the control (something like
Leave) I don't see how you could avoid writing code in each of these other
controls to call the notify event, or function, or whatever you use to
implement it. So you're saying that you have to subclass all these controls
because the events already given don't do what you need? I would agree with
the last two posters. Either make each of your controls call a public method
on the notifying control, with some sort of identification of the sender, or
make a new event delegate and add that event to each of the notifying
controls, let the class receiving the notification subscribe to each of
those events, and then add logic in each of the controls with the events to
fire the event when appropriate.

Chris

"Tom Bean" <tb***@t-a-c.com> wrote in message
news:#1**************@TK2MSFTNGP10.phx.gbl...
Andrew,

That would mean that all kinds of objects, like textboxes, comboboxes,
listboxes...would have to have the same notify event. That's a lot of
duplicate code in the other objects to just be able to notify a single
object that something has happened,

Tom

"andrew lowe" <andrew [dot] lowe [at] geac [.] com> wrote in message
news:er****************@tk2msftngp13.phx.gbl...

"Tom Bean" <tb***@t-a-c.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Can events be used to notify an object that something has happened and it needs to take some action?

Most of the documentation on events makes them sound like they work the other way around, that is, an object raises an event to inform other objects
that something happened. I need the ability for many objects to
notify a single object that some event has occurred. e.g. similar to LostFocus.


Tom,

Whats wrong with having the single object subscribe to the each of the

other
objects "notify" event(s) ?

andrew


Nov 15 '05 #3
Chris,

I did as you and the others recommended and implemented a public method that
the other controls can call to notify the control about the event. After
thinking about it, I suppose that's not any different than using
SendMessage() in C++ which in the final analysis is just a call to a public
method.

Thanks,
Tom

"Chris Capel" <ch***@ibanktech.net.zerospam> wrote in message
news:O3****************@TK2MSFTNGP10.phx.gbl...
If the event you need isn't already provided by the control (something like Leave) I don't see how you could avoid writing code in each of these other
controls to call the notify event, or function, or whatever you use to
implement it. So you're saying that you have to subclass all these controls because the events already given don't do what you need? I would agree with the last two posters. Either make each of your controls call a public method on the notifying control, with some sort of identification of the sender, or make a new event delegate and add that event to each of the notifying
controls, let the class receiving the notification subscribe to each of
those events, and then add logic in each of the controls with the events to fire the event when appropriate.

Chris

"Tom Bean" <tb***@t-a-c.com> wrote in message
news:#1**************@TK2MSFTNGP10.phx.gbl...
Andrew,

That would mean that all kinds of objects, like textboxes, comboboxes,
listboxes...would have to have the same notify event. That's a lot of
duplicate code in the other objects to just be able to notify a single
object that something has happened,

Tom

"andrew lowe" <andrew [dot] lowe [at] geac [.] com> wrote in message
news:er****************@tk2msftngp13.phx.gbl...

"Tom Bean" <tb***@t-a-c.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> Can events be used to notify an object that something has happened and
it
> needs to take some action?
>
> Most of the documentation on events makes them sound like they work the > other way around, that is, an object raises an event to inform other
objects
> that something happened. I need the ability for many objects to

notify
a
> single object that some event has occurred. e.g. similar to

LostFocus.
Tom,

Whats wrong with having the single object subscribe to the each of the

other
objects "notify" event(s) ?

andrew



Nov 15 '05 #4

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

Similar topics

3
by: Sasha | last post by:
Hi everyone, Here is my problem: I have the following classes: - DataNode - this class is designed to hold some data and will be contained in a tree like data structure DataTree. When...
6
by: Saso Zagoranski | last post by:
Hi! How can I unregister all the events registered to a control? I have seen a piece of code in another thread, which gets all the registered handlers for a specific event. Let's say I have a...
14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
2
by: Bob Rundle | last post by:
I have the following code, which appears to be working. However it doesn't look right. The part I am wondering about is the logic in DisconnectEvents(). This logic creates a new delegate and...
4
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...
11
by: Nicky Smith | last post by:
Hello, I'm studying a book on VB.net Win apps, and I'm reading a section on events and delegates and raising events. Is it just me, or is this not just subs dressed up as something else? I...
30
by: Burkhard | last post by:
Hi, I am new to C# (with long year experience in C++) and I am a bit confused by the language construct of events. What is it I can do with events that I cannot do with delegates? At the moment...
5
by: Richard Maher | last post by:
Hi, Here I mean "User" in the Programmer or Javascript sense. I merely wish to programmatically trigger an Event. It would be absolutely fantastic if there was a (Form level?) ONUSEREVENT() and...
14
by: xoozlez | last post by:
Hi there, I have a registration form where I like to filter out the past events of 2007. This is the code I am using : strSQL = "SELECT EventID, EventName, EventDateBegin, EventDateEnd,...
1
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.