473,748 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generic event handlers possible? Accept "e As EventArgs" when event passes something more specific?


Is there any way to create a generic event handler that can be
subscribed to any event? If I have a sub..

Private Sub DataTable_Somet hingChanged(sen der As Object, e As
System.EventArg s)

and subscribe it to

AddHandler dataTable.Colum nChanged, AddressOf SomethingChange d

it gives me this error

Method 'Private Sub DataTable_Somet hingChanged(sen der As Object, e As
System.EventArg s)' does not have the same signature as delegate
'Delegate Sub DataColumnChang eEventHandler(s ender As Object, e As
System.Data.Dat aColumnChangeEv entArgs)'.
Even though the signature doesn't match exactly, it is still
compatible. If it wasn't a delegate but just a regular method call I
could pass an instance of DataColumnChang eEventArgs to a variable
expecting EventArgs. But that appears no to be the case with
delegates.

Any work-around? What I want to do is have one function that listens
to several events and at this point it seems I need a separate
function for each since they need different signatures (I don't care
about the details at all, I just want to know the event was
triggered).

Thanks,

Sam
B-Line is now hiring one VB.NET developer for
WinForms + WebServices position with ASPX in future.
Seaking mid to senior level developer. For
information or to apply e-mail sam_blinex_com.
Nov 21 '05 #1
1 1579
Is there any way to create a generic event handler that can be
subscribed to any event?
In v1.x, no. In v2.0 the runtime supports it, but I'm not sure VB.NET
will.

Any work-around?


Create multiple event handlers that all call a common method.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2

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

Similar topics

2
9193
by: Jon Davis | last post by:
The garbage handler in the .NET framework is handy. When objects fall out of scope, they are automatically destroyed, and the programmer doesn't have to worry about deallocating the memory space for those objects. In fact, all the programmer has to worry about is the total sum of objects loaded into RAM at any known point. Memory leaks are not a problem. .... So one would like to think. The reality is that delegates and event...
0
1112
by: msnews.microsoft.com | last post by:
I have a delegate defined as ... public delegate void MessageHandler<T>(T t, object arg) where T : MessageBase, new(); and I am trying to create an event to handle that delegate (shown below) ... but since the enclosing class doesn't have T defined I can't define it here either and I get a comilation error. (Please note, that the method defined below MessageHandler works fine.)
24
7700
by: Charles Law | last post by:
When I click a button I don't want the click event to fire. Is this possible? In fact, what I would really like is to be able to intercept the click event, perform some action, and then prevent the click from passing through to the button. Any help or suggestions much appreciated. Charles
6
10412
by: David Veeneman | last post by:
I have several events that pass a value in their event args. One event passes an int, another a string, another a DateTime, and so on. Rather than creating a separate set of event args for each type, I have created a generic event args class that looks like this: public class ItemChangingEventArgs<T> { ... }
1
1408
by: bill | last post by:
I'm using VS2005. I am dynamically adding a Textbox control to a Placeholder control in the page_load event of the form, but the event handler isn't firing. What am I doing wrong? Thanks Bill
6
3943
by: hemant.singh | last post by:
Hi all, I am trying to get a way by which I'll know exactly when user goes out of my site by clicking on close button in browser, So that w/e user click close button in browser, I can send a signal to server. This seems to be achievable with body unload events, but it is little too much, as even if user navigate within my site, this event will be generated, this can be avoided by handling onclick of each link, so that I'll know exactly...
2
5398
by: Tom_F | last post by:
To comp.databases.ms-access -- I would like to trigger an event when I close a form -- but ONLY when the data in the "RecordSource" table has been updated. I tried using the AfterUpdate event, but it fires multiple times when the form is closed ... and I only want my event to be triggered once. Could someone tell me a good way to do this? I'm using Microsoft Access 2003. Thanks very much! --Tom
0
1527
by: epoxyparser | last post by:
Hi all, I work as a glue coder and often have to interface existing mechanisms with other platforms. Creating bridge code between command-line functionality and desktop GUIs takes up a lot of that definition, along with creating abstraction layers for older-style C code. I've been working with .net (almost exclusively with C++.net, just a bit of C#) to create end-user interfaces with a relatively good deal of success (I'm used to ansi/STL and...
5
1810
by: gnassar | last post by:
Essentially my problem is that .NET 2005 is removing my event handlers. There's no real special things about my project, it just continually removes them all. It starts on the open of a solution. The screen flashes and immediately I can undo something. I look at the undo list and it says designer generated code. When I undo it, all of my event handlers come back. This is a very annoying issue has anyone solved this problem? -G
0
8991
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
8830
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,...
1
9321
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,...
0
8242
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
6796
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
6074
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();...
0
4602
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
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2782
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.