473,785 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check if an event is already handled

I created a windows form control that inherits from the standard .Net
DataGridView control, to which I've added custom functionality.
Instead of using the standard control in my applications, I use my
customized version. I have an event handler in the custom control for
the KeyDown event that simulates a double-click on the selected grid
row when the user presses the enter key. This is working just fine.

Now, some screens that are using this custom control handle the grid's
KeyDown event themselves, so in those cases I don't want the KeyDown
event handler in the custom control class to handle the event. Is
there some check I can perform in the custom control, without adding
anything to the screens that use it, to see if the event is already
being handled? Something like this:

private void MyDataGridView_ KeyDown(object sender, KeyEventArgs e)
{
if ( /* check if the KeyDown event is already being handled
elsewhere */ )
{
return;
}
else
{
SimulateDoubleC lick();
}
}

Apparently, GetInvocationLi st() is supposed to return all of the
handlers for an event, but "this.KeyDown.G etInvocationLis t()" does not
compile. Thanks!

Aug 22 '07 #1
6 6102
<mj****@yahoo.c omwrote in message
news:11******** *************@e 9g2000prf.googl egroups.com...
>I created a windows form control that inherits from the standard .Net
DataGridView control, to which I've added custom functionality.
Instead of using the standard control in my applications, I use my
customized version. I have an event handler in the custom control for
the KeyDown event that simulates a double-click on the selected grid
row when the user presses the enter key. This is working just fine.

Now, some screens that are using this custom control handle the grid's
KeyDown event themselves, so in those cases I don't want the KeyDown
event handler in the custom control class to handle the event. Is
there some check I can perform in the custom control, without adding
anything to the screens that use it, to see if the event is already
being handled? Something like this:

private void MyDataGridView_ KeyDown(object sender, KeyEventArgs e)
{
if ( /* check if the KeyDown event is already being handled
elsewhere */ )
{
return;
}
else
{
SimulateDoubleC lick();
}
}

Apparently, GetInvocationLi st() is supposed to return all of the
handlers for an event, but "this.KeyDown.G etInvocationLis t()" does not
compile. Thanks!
My experience is with .NET 1.1 (no DataGridView), but since you're deriving
from it, I suspect you can override the OnKeyDown method instead of handling
the KeyDown event.

Then you could do something like this:

protected override void OnKeyDown(KeyEv entArgs ke)
{
base.OnKeyDown( ke);
if (ke.Handled)
{
return;
}
... do your stuff here. ...
}


Aug 22 '07 #2

<mj****@yahoo.c omwrote in message
news:11******** *************@e 9g2000prf.googl egroups.com...
>I created a windows form control that inherits from the standard .Net
DataGridView control, to which I've added custom functionality.
Instead of using the standard control in my applications, I use my
customized version. I have an event handler in the custom control for
the KeyDown event that simulates a double-click on the selected grid
row when the user presses the enter key. This is working just fine.

Now, some screens that are using this custom control handle the grid's
KeyDown event themselves, so in those cases I don't want the KeyDown
event handler in the custom control class to handle the event. Is
there some check I can perform in the custom control, without adding
anything to the screens that use it, to see if the event is already
being handled? Something like this:

private void MyDataGridView_ KeyDown(object sender, KeyEventArgs e)
{
if ( /* check if the KeyDown event is already being handled
elsewhere */ )
{
return;
}
else
{
SimulateDoubleC lick();
}
}

Apparently, GetInvocationLi st() is supposed to return all of the
handlers for an event, but "this.KeyDown.G etInvocationLis t()" does not
compile. Thanks!
No, that's for a delegate. A custom event cannot be treated as a delegate
field (although a delegate field can be used to create an event).
Aug 22 '07 #3
<mj****@yahoo.c omschrieb:
Now, some screens that are using this custom control handle the grid's
KeyDown event themselves, so in those cases I don't want the KeyDown
event handler in the custom control class to handle the event. Is
there some check I can perform in the custom control, without adding
anything to the screens that use it, to see if the event is already
being handled? Something like this:

private void MyDataGridView_ KeyDown(object sender, KeyEventArgs e)
{
if ( /* check if the KeyDown event is already being handled
elsewhere */ )
{
return;
}
else
{
SimulateDoubleC lick();
}
}

Apparently, GetInvocationLi st() is supposed to return all of the
handlers for an event, but "this.KeyDown.G etInvocationLis t()" does not
compile.
That's not possible for Windows Forms controls' events from outside the
class defining them because the delegate variable holding the handlers is
not exposed by the object model.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Aug 22 '07 #4
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.atwrote in message
news:uT******** ******@TK2MSFTN GP06.phx.gbl...
<mj****@yahoo.c omschrieb:
>Now, some screens that are using this custom control handle the grid's
KeyDown event themselves, so in those cases I don't want the KeyDown
event handler in the custom control class to handle the event. Is
there some check I can perform in the custom control, without adding
anything to the screens that use it, to see if the event is already
being handled? Something like this:

private void MyDataGridView_ KeyDown(object sender, KeyEventArgs e)
{
if ( /* check if the KeyDown event is already being handled
elsewhere */ )
{
return;
}
else
{
SimulateDoubleC lick();
}
}

Apparently, GetInvocationLi st() is supposed to return all of the
handlers for an event, but "this.KeyDown.G etInvocationLis t()" does not
compile.

That's not possible for Windows Forms controls' events from outside the
class defining them because the delegate variable holding the handlers is
not exposed by the object model.
You can get to it through reflection and test the event handler for null. If
the event is handled, however, and the e.Handled is set to true, then he can
simply override the OnKeyDown handler and check for e.Handled.

I'm not saying reflection is always the best answer, but sometimes it does
come in handy.

Aug 22 '07 #5
Thanks, I will research doing this through reflection.

I guess the KeyDown event is kind of a special case since there is the
Handled flag already in the event args, but really I'm looking for a
more general approach, since I would like to do the same type of thing
for other events that might not have such a flag in their event args.

Aug 22 '07 #6
<mj****@yahoo.c omwrote in message
news:11******** **************@ j4g2000prf.goog legroups.com...
Thanks, I will research doing this through reflection.

I guess the KeyDown event is kind of a special case since there is the
Handled flag already in the event args, but really I'm looking for a
more general approach, since I would like to do the same type of thing
for other events that might not have such a flag in their event args.
Reflection isn't always a good "general approach", though in this case, it
may be the only choice.

It depends on who your users are and what their security settings are,
reflection is sometimes not allowed. Also, reflection can be slow, which is
another reason it's not always a good general approach.
Aug 23 '07 #7

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

Similar topics

5
2109
by: Alan Zhong | last post by:
i am trying to similate an "ENTER" as a key to switch focus in a sequence of text inputs. i don't want to use "event.keyCode" since i want to do additional testing before i decide which text input i want to focus next. the following are the test code i have, whenever i hit "enter", it will act clicking the submit button. what can i do to avoid this problem? <!-- ############# code begins here ############ --> <html> <head>
18
2889
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 that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
9
15859
by: Susan Bricker | last post by:
I am currently using the OnDirty event of a Form to detect whether any fields have been modified. I set a boolean variable. Then, if the Close button is clicked before the Save button, I can put up a message on the screen that will tell the user that "Data has been changed, do you wish to Save the record before Closing this window?" I think I've just discovered this only works if the record that is being displayed/modified it not a...
20
41902
by: anthonymelillo | last post by:
Is there any way to check the entry in a text box and make sure it is numeric ? Also, can I catch the enter key and make it call a button click event ? Sorry if this sounds stupid, but I am trying to come to grips with the differences in .Net since all my prior programming was done in VB6 Thanks --
12
4143
by: Jack Russell | last post by:
My unstanding of all VB up to and including vb6 is that an event could not "interrupt" itself. For instance if you had a timer event containing a msgbox then you would only get one message. However in vb.net you get continual messages (even setting the system modal property). Firstly, are these two assumptions right and if so what is the approved
2
2137
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 database. This works fine. However, I attempt to notify the user when data accesses occur. The way I attempt to accomplish this is by changing the background color of a label on the form the user is looking at. I use red for when the database is...
7
1718
by: Michael D. Ober | last post by:
Is there anyway to raise an event from a class and require that any program using that class (not just inheritance) have an event handler for specific events in the class? In my case, some events don't need to be handled, but some must be handled by the program that uses the class. I'm looking for something along the lines of Class MyClass Event OptionalEvent(parms) Event RequiredEvent(parms)
9
2471
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the post event will always execuate after the system is completed... - I want to wrap this functionality in a framework, so I could possibly have 3 or 4 levels of inherited objects that need to have these pre / post events executed before and after the...
0
9647
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
9485
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
10356
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
10161
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...
0
9958
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
8986
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...
0
5390
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
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
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

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.