473,387 Members | 1,364 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,387 software developers and data experts.

Event handling

VC
I created an usercontrol ACTRL. and I fired an event from the ACTRL.
in my form application, do all ACTRL controls have to do "+=" to sign
up the event? my problem is if the ACTRL control in the form app
doesn't sign up the event, the application will throw exception
"Object reference not set to an instance of an object" during the run
time.
Nov 15 '05 #1
3 1885
VC,

If you want to hook up a method on ACTRL to an event on the form, then
yes, you have to sign up for the event using the += operator. Or, if you
want other methods to be hooked up to an event that ACTRL fires, then you
need to hook those up using the same operator.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"VC" <us********@yahoo.com> wrote in message
news:be**************************@posting.google.c om...
I created an usercontrol ACTRL. and I fired an event from the ACTRL.
in my form application, do all ACTRL controls have to do "+=" to sign
up the event? my problem is if the ACTRL control in the form app
doesn't sign up the event, the application will throw exception
"Object reference not set to an instance of an object" during the run
time.

Nov 15 '05 #2
VC
Nicholas,

Thank you very much for your feedback. I have read a lot of messages
you posted in Google Group, they are very helpful.

In my project(C#,.NET). some of usercontrols(ACTRL) need hook up to
the event that ACTRL fires. and some of them don't need. right now the
situation is that all of them have to be signed up to the event by
"+=". otherwise they throw "Object reference not set to an instance of
an object" exception.
what I want to do is if you need receive the event from the ACTRL,
sign up "+=" to event. if not, don't sign up. please let me know
anything wrong in my code.
Here is my code look like:

public delegate void InkCtrlUpdatedEvent(object o, string str);

public class ACTRL: System.Windows.Forms.UserControl
{
:
:
public event InkCtrlUpdatedEvent InkCtrlCellUpdated;
:
:
private void fireEvent(string str)
{
InkCtrlCellUpdated(this,str);
}
}

Again, thanks for the help.


us********@yahoo.com (VC) wrote in message news:<be**************************@posting.google. com>...
I created an usercontrol ACTRL. and I fired an event from the ACTRL.
in my form application, do all ACTRL controls have to do "+=" to sign
up the event? my problem is if the ACTRL control in the form app
doesn't sign up the event, the application will throw exception
"Object reference not set to an instance of an object" during the run
time.

Nov 15 '05 #3
Try putting changing your fireEvent method to have the following code:

if(null != InkCtrlCellUpdated)
{
InkCtrlCellUpdated(this,str);
}

- Scott Wagner

VC wrote:
Nicholas,

Thank you very much for your feedback. I have read a lot of messages
you posted in Google Group, they are very helpful.

In my project(C#,.NET). some of usercontrols(ACTRL) need hook up to
the event that ACTRL fires. and some of them don't need. right now the
situation is that all of them have to be signed up to the event by
"+=". otherwise they throw "Object reference not set to an instance of
an object" exception.
what I want to do is if you need receive the event from the ACTRL,
sign up "+=" to event. if not, don't sign up. please let me know
anything wrong in my code.
Here is my code look like:

public delegate void InkCtrlUpdatedEvent(object o, string str);

public class ACTRL: System.Windows.Forms.UserControl
{
:
:
public event InkCtrlUpdatedEvent InkCtrlCellUpdated;
:
:
private void fireEvent(string str)
{
InkCtrlCellUpdated(this,str);
}
}

Again, thanks for the help.


us********@yahoo.com (VC) wrote in message news:<be**************************@posting.google. com>...
I created an usercontrol ACTRL. and I fired an event from the ACTRL.
in my form application, do all ACTRL controls have to do "+=" to sign
up the event? my problem is if the ACTRL control in the form app
doesn't sign up the event, the application will throw exception
"Object reference not set to an instance of an object" during the run
time.


Nov 15 '05 #4

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

Similar topics

7
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. ...
1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
4
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
4
by: hillcountry74 | last post by:
Hi, I'm a newbie and trying to understand event handling in c#. I have understood handling events using delelgate objects. But not this method- "Event handling by overriding the virtual...
3
by: Ashok Kumar K | last post by:
Hi all, Where can I get some insight on using the __hook, __unhook, event_source and event_receiver for specifically COM events. The documentation given in MSDN is very minimal. I have the...
2
by: Paul E. Orman | last post by:
I have a piece of VB code (.NET 1.1 - VB 2003) that loads data from a database through a timer. So the timer is setup and from it I call the procedure that loads the latest records from the...
4
by: mflll | last post by:
I am looking into the different techniques of handling arrays of edit boxes in Java Script. The first program below works fine. However, are there better ways of doing this, where the person...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.