473,803 Members | 3,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

EventArgs that return values... How do i replicate?

Consider the TextBox Control. It has a KeyPress event of type
KeyPressEventHa ndler which passes a KeyPressEventAr gs to whatever
method is assigned to the event.

When you set e.Handled = false within the assigned method, it disallows
the keypress.

Suppose I have a usercontrol consisting of a textbox, a button, and a
listview. When the user enters something in the textbox and clicks the
button, the textbox's text gets added to the listview as a new item.

Suppose I want to create an event that gets invoked on the button
click, called BeforeAddTextTo Listview, which will be of type
BeforeAddTextTo ListviewHandler and pass
BeforeAddTextTo ListviewEventAr gs to whatever method is assigned to the
event.

Suppose BeforeAddTextTo ListviewEventAr gs has a property called Allowed.
When Allowed=true, the addition to the listview will occur.

This gives the user of the usercontrol the ability to control what is
allowed to go into the listview.

So in my the usercontrols class I have:

public event BeforeAddTextTo ListviewHandler BeforeAddTextTo Listview;

public delegate void BeforeAddTextTo ListviewHandler (object sender,
BeforeAddTextTo ListviewEventAr gs e);

private void btnAddTextToLis tView_Click(obj ect sender, EventArgs e)
{

BeforeAddTextTo ListviewEventAr gs e = new
BeforeAddTextTo ListviewEventAr gs();

if (BeforeAddTextT oListview!= null)
{
BeforeAddTextTo Listview(this, e);
}

if (e.Allowed)
{
//add text to listview
}

}

The problem here is that e is not passed by reference, so it wont know
the value of allowed set by the user.

I could just define BeforeAddTextTo ListviewHandler as:

public delegate void BeforeAddTextTo ListviewHandler (object sender, ref
BeforeAddTextTo ListviewEventAr gs e);

and pass e by reference. Then I would get what i want.

However, the KeyPressEventAr gs in KeyPressEventHa ndler is not passed
by reference.

So what I want to know and what i want to do is...
How does the KeyPressEventHa ndler get the e.Handled back when e does
not have the ref keyword preceding it?
How can i replicate this?

Any help, comments, suggestions greatly appreciated.

Thanks,
Mike

Sep 12 '06 #1
6 2419
nevermind...

I tried it without the ref and it worked, so I just answered my own
question.... for some reason i thought it wouldn't.

I guess the ref is assumed when you are dealing with eventhandlers.

Mi************@ gmail.com wrote:
Consider the TextBox Control. It has a KeyPress event of type
KeyPressEventHa ndler which passes a KeyPressEventAr gs to whatever
method is assigned to the event.

When you set e.Handled = false within the assigned method, it disallows
the keypress.

Suppose I have a usercontrol consisting of a textbox, a button, and a
listview. When the user enters something in the textbox and clicks the
button, the textbox's text gets added to the listview as a new item.

Suppose I want to create an event that gets invoked on the button
click, called BeforeAddTextTo Listview, which will be of type
BeforeAddTextTo ListviewHandler and pass
BeforeAddTextTo ListviewEventAr gs to whatever method is assigned to the
event.

Suppose BeforeAddTextTo ListviewEventAr gs has a property called Allowed.
When Allowed=true, the addition to the listview will occur.

This gives the user of the usercontrol the ability to control what is
allowed to go into the listview.

So in my the usercontrols class I have:

public event BeforeAddTextTo ListviewHandler BeforeAddTextTo Listview;

public delegate void BeforeAddTextTo ListviewHandler (object sender,
BeforeAddTextTo ListviewEventAr gs e);

private void btnAddTextToLis tView_Click(obj ect sender, EventArgs e)
{

BeforeAddTextTo ListviewEventAr gs e = new
BeforeAddTextTo ListviewEventAr gs();

if (BeforeAddTextT oListview!= null)
{
BeforeAddTextTo Listview(this, e);
}

if (e.Allowed)
{
//add text to listview
}

}

The problem here is that e is not passed by reference, so it wont know
the value of allowed set by the user.

I could just define BeforeAddTextTo ListviewHandler as:

public delegate void BeforeAddTextTo ListviewHandler (object sender, ref
BeforeAddTextTo ListviewEventAr gs e);

and pass e by reference. Then I would get what i want.

However, the KeyPressEventAr gs in KeyPressEventHa ndler is not passed
by reference.

So what I want to know and what i want to do is...
How does the KeyPressEventHa ndler get the e.Handled back when e does
not have the ref keyword preceding it?
How can i replicate this?

Any help, comments, suggestions greatly appreciated.

Thanks,
Mike
Sep 12 '06 #2
Michael,

I think you may be a little confused about value and reference types
and how they behave with the different parameter passing mechanisms.
Maybe the following article will help clear things up.

http://www.yoda.arachsys.com/csharp/parameters.html

Brian

Mi************@ gmail.com wrote:
nevermind...

I tried it without the ref and it worked, so I just answered my own
question.... for some reason i thought it wouldn't.

I guess the ref is assumed when you are dealing with eventhandlers.
Sep 12 '06 #3
thanks.

Brian Gideon wrote:
Michael,

I think you may be a little confused about value and reference types
and how they behave with the different parameter passing mechanisms.
Maybe the following article will help clear things up.

http://www.yoda.arachsys.com/csharp/parameters.html

Brian

Mi************@ gmail.com wrote:
nevermind...

I tried it without the ref and it worked, so I just answered my own
question.... for some reason i thought it wouldn't.

I guess the ref is assumed when you are dealing with eventhandlers.
Sep 12 '06 #4
On a side note, for your class, I would not use an Allowed property.
Rather, I would derive the EventArgs class from CancelEventArgs , found in
the System.Componen tModel namespace.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

<Mi************ @gmail.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
thanks.

Brian Gideon wrote:
>Michael,

I think you may be a little confused about value and reference types
and how they behave with the different parameter passing mechanisms.
Maybe the following article will help clear things up.

http://www.yoda.arachsys.com/csharp/parameters.html

Brian

Mi************@ gmail.com wrote:
nevermind...

I tried it without the ref and it worked, so I just answered my own
question.... for some reason i thought it wouldn't.

I guess the ref is assumed when you are dealing with eventhandlers.

Sep 12 '06 #5
Thanks for the note.
The reason I create my own EventArgs class with an allowed property, is
that i also have a text property to pass the user the text that needs
to be analyzed to method so that the method can determine if this text
should be allowed to be added to the listview.
Nicholas Paldino [.NET/C# MVP] wrote:
On a side note, for your class, I would not use an Allowed property.
Rather, I would derive the EventArgs class from CancelEventArgs , found in
the System.Componen tModel namespace.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

<Mi************ @gmail.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
thanks.

Brian Gideon wrote:
Michael,

I think you may be a little confused about value and reference types
and how they behave with the different parameter passing mechanisms.
Maybe the following article will help clear things up.

http://www.yoda.arachsys.com/csharp/parameters.html

Brian

Mi************@ gmail.com wrote:
nevermind...

I tried it without the ref and it worked, so I just answered my own
question.... for some reason i thought it wouldn't.

I guess the ref is assumed when you are dealing with eventhandlers.
Sep 12 '06 #6
Michael,

I understand that, but what I am saying is that instead of using the
EventArgs class as your base, use the CancelEventArgs and you won't have to
worry about the Cancel property, it's there for you in the base. Then you
can add the properties that you need in your specialization.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
<Mi************ @gmail.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
Thanks for the note.
The reason I create my own EventArgs class with an allowed property, is
that i also have a text property to pass the user the text that needs
to be analyzed to method so that the method can determine if this text
should be allowed to be added to the listview.
Nicholas Paldino [.NET/C# MVP] wrote:
>On a side note, for your class, I would not use an Allowed property.
Rather, I would derive the EventArgs class from CancelEventArgs , found in
the System.Componen tModel namespace.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

<Mi*********** *@gmail.comwrot e in message
news:11******* *************** @i42g2000cwa.go oglegroups.com. ..
thanks.

Brian Gideon wrote:
Michael,

I think you may be a little confused about value and reference types
and how they behave with the different parameter passing mechanisms.
Maybe the following article will help clear things up.

http://www.yoda.arachsys.com/csharp/parameters.html

Brian

Mi************@ gmail.com wrote:
nevermind...

I tried it without the ref and it worked, so I just answered my own
question.... for some reason i thought it wouldn't.

I guess the ref is assumed when you are dealing with eventhandlers.


Sep 12 '06 #7

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

Similar topics

1
1496
by: James E Koehler | last post by:
I have a table that contains mostly zero entries but has a few non-zero values scattered randomly in the table as VERSION 1 below. What I want to do is fill in the zeroed values with copies of the non-zero values resulting in the modified version of the table as shown in VERSION 2 below. In other words, I want to replicate entries following the entries as originally supplied. I would like someone to supply me with the MySQL code that...
2
2537
by: Chandra Mohan | last post by:
Getting 0 padded values in the columns. Hi All, I have a requirement to convert a integer to string and display it in Sql server with fixed length say 3 chars. (in c, we wud use %03d in printf) If the number is small say, 9 then it has to be displayed as 009, 56 -> 056, 897-> 897, 6786 -> xxx
2
2228
by: db2group88 | last post by:
we are using db2 udb v8.2 Express edition on windows 2003,we use third party vendor software to help replicate one server to another. Production server has three instances, each instances has one database under it. So we would see three folders on D drive: DB2 folder, TEST folder and EDU folder, each database has 5 tablespaces and they exist on F drive. So I told the client to replicate the three instance folders on D and the data folder...
2
4675
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info Center: To return a result set from a procedure to the originating application, use the WITH RETURN TO CLIENT clause. When WITH RETURN TO CLIENT is specified on a result set, no nested procedures can access the result set.
1
8059
by: annie | last post by:
Hi all, I have recently ported my Access 2000 app to SQL Server, keeping the Access client as the front end using linked tables. I am also using triggers on my SQL tables to trap orphan records and validate added data. My question is..
5
1656
by: Abdessamad Belangour | last post by:
Hi all, I'm working on a Windows application composed of two forms : form1 and form2. form1 calls form2 which has two buttons : OK and Cancel. The form1 needs to know which of form2 buttons were clicked and to get some form2 processed values . private void OK_Click(object sender, System.EventArgs e) { // do proccessing and return a value
1
4696
by: Jack Addington | last post by:
I have a 3rd party object that fires an itemchanged event when someone edits some data on a form. This event has a custom eventArgs that has a field called ActionCode. In the code of the event, if you set this ActionCode to various values the control will respond in various ways (reject, reject change field, accept, etc). I am trying to understand exactly how that works as I am trying to extend the control and add more processing s...
3
6543
by: Yangtsi River | last post by:
Hi, in any event procudure,there is two paras:sender As Object, e As EventArgs, i copied them-not know what they are about, and my ASPX works. I guess the sender is the control by which I triggered this sub, and what is EventArgs then? I am passing a third para to the sub, that is mysub("jim",sender As Object, e As EventArgs), the sub is defined like :
1
1494
by: mg | last post by:
Is there a way to replicate the GAC on a win2003 server to another similar server? We are currently using DFS to replicate files, and I do not see how to use DFS to replicate the GAC. -- mg we'll burn that bridge when we get to it
0
9700
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
9564
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
10546
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10292
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7603
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
6841
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.