473,569 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET Event handling subs

Hi, I need to "save" in a variable the event handler sub of a control's
event, then perform some process, and finally "restore" the originally saved
event handler.

Example in pseudo-code:

1) Save cmbMyCombo's event handler for SelectedIndexCh ange event.

2) Assign a temporary event handler sub to cmbMyCombo's for its
SelectedIndexCh ange event.
AddHandler cmbMyCombo.Sele ctedIndexChange d, AddressOf
cmbMyCombo_Sele ctedIndexChange d_Temporary

3) Do some processing...

4) Restore the previously-saved event handler sub for the
SelectedIndexCh ange event to cmbMyCombo.

How can this be accomplished? Thanks in advance.

Regards,

Rick
Jan 4 '06 #1
5 1886
What are you really trying to accomplish? Why does it matter if the event
handler is changed during the processing of the event - it's not going to
have a chance to fire at this point anyway.

"Richard Grant" <Ri**********@d iscussions.micr osoft.com> wrote in message
news:37******** *************** ***********@mic rosoft.com...
Hi, I need to "save" in a variable the event handler sub of a control's
event, then perform some process, and finally "restore" the originally
saved
event handler.

Example in pseudo-code:

1) Save cmbMyCombo's event handler for SelectedIndexCh ange event.

2) Assign a temporary event handler sub to cmbMyCombo's for its
SelectedIndexCh ange event.
AddHandler cmbMyCombo.Sele ctedIndexChange d, AddressOf
cmbMyCombo_Sele ctedIndexChange d_Temporary

3) Do some processing...

4) Restore the previously-saved event handler sub for the
SelectedIndexCh ange event to cmbMyCombo.

How can this be accomplished? Thanks in advance.

Regards,

Rick

Jan 4 '06 #2
Thanks for your help. I'm writing a generic method that receives a combox as
a parameter, temporarily removes or replaces one of its event handlers, and
in the Finally clause, as part of the cleanup, needs to restore the original
event handler so the combobox continue working as before. In C/C++ it'd be
down to saving the address of the subroutine as a pointer, but how can this
be done in VB.NET? RemoveHandler doesn't return anything... Thanks in advance.

Regards,

Rick
"Marina" wrote:
What are you really trying to accomplish? Why does it matter if the event
handler is changed during the processing of the event - it's not going to
have a chance to fire at this point anyway.

"Richard Grant" <Ri**********@d iscussions.micr osoft.com> wrote in message
news:37******** *************** ***********@mic rosoft.com...
Hi, I need to "save" in a variable the event handler sub of a control's
event, then perform some process, and finally "restore" the originally
saved
event handler.

Example in pseudo-code:

1) Save cmbMyCombo's event handler for SelectedIndexCh ange event.

2) Assign a temporary event handler sub to cmbMyCombo's for its
SelectedIndexCh ange event.
AddHandler cmbMyCombo.Sele ctedIndexChange d, AddressOf
cmbMyCombo_Sele ctedIndexChange d_Temporary

3) Do some processing...

4) Restore the previously-saved event handler sub for the
SelectedIndexCh ange event to cmbMyCombo.

How can this be accomplished? Thanks in advance.

Regards,

Rick


Jan 4 '06 #3
I still don't understand why you need to temporarily change what the event
handler is.

If in the handler for event A, you don't want event B to fire, then I don't
think getting rid of the handler is the way to go. Because if the user can
still interact with the control, then that is the real problem. If the user
can change the selected index and just not have the event fire, after all is
said and done the user will have changed the value of the dropdown, but no
event would have fired. Because no event fired, the handler didn't run, and
now your form is in an inconsistent state.

Again I ask what is it you are trying to accomplish - in the bigger sense.
What functionality are you trying to give your application? I understand the
mechanics you are trying to achieve.

I am not sure if there is a way to get the invocation list for a given
object's event. That makes sense to me, because that list should be private
to the object itself, and something using the object shouldn't just be able
to get a list of all the listeners for a particular event.

"Richard Grant" <Ri**********@d iscussions.micr osoft.com> wrote in message
news:89******** *************** ***********@mic rosoft.com...
Thanks for your help. I'm writing a generic method that receives a combox
as
a parameter, temporarily removes or replaces one of its event handlers,
and
in the Finally clause, as part of the cleanup, needs to restore the
original
event handler so the combobox continue working as before. In C/C++ it'd be
down to saving the address of the subroutine as a pointer, but how can
this
be done in VB.NET? RemoveHandler doesn't return anything... Thanks in
advance.

Regards,

Rick
"Marina" wrote:
What are you really trying to accomplish? Why does it matter if the event
handler is changed during the processing of the event - it's not going to
have a chance to fire at this point anyway.

"Richard Grant" <Ri**********@d iscussions.micr osoft.com> wrote in message
news:37******** *************** ***********@mic rosoft.com...
> Hi, I need to "save" in a variable the event handler sub of a control's
> event, then perform some process, and finally "restore" the originally
> saved
> event handler.
>
> Example in pseudo-code:
>
> 1) Save cmbMyCombo's event handler for SelectedIndexCh ange event.
>
> 2) Assign a temporary event handler sub to cmbMyCombo's for its
> SelectedIndexCh ange event.
> AddHandler cmbMyCombo.Sele ctedIndexChange d, AddressOf
> cmbMyCombo_Sele ctedIndexChange d_Temporary
>
> 3) Do some processing...
>
> 4) Restore the previously-saved event handler sub for the
> SelectedIndexCh ange event to cmbMyCombo.
>
> How can this be accomplished? Thanks in advance.
>
> Regards,
>
> Rick


Jan 4 '06 #4
Richard,
In addition to the other comments:

| Hi, I need to "save" in a variable the event handler sub of a control's
| event, then perform some process, and finally "restore" the originally
saved
| event handler.
There may be multiple event handler subs for a single events, is there a
specific handler you want to save or do you want to save the entire list?

The "problem" is that the list of event handlers are not publicly available.
Different classes store the list differently. A number of framework classes
store the handlers in the Component.Event s member:

http://msdn2.microsoft.com/en-us/lib...US,VS.80).aspx

While the convention for VB classes is a hidden field named for the Event,
for example the MyValueChanged event keeps the list in the
MyValueChangeEv ent field.

VB 2005 can use Custom Events to store the list of event handlers in the
Component.Event s member.

http://www.panopticoncentral.net/arc...8/06/1545.aspx

Gaining access to this list for classes other then your own, is problematic
at best, in that how the list is stored is an implementation detail that
could change...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Richard Grant" <Ri**********@d iscussions.micr osoft.com> wrote in message
news:37******** *************** ***********@mic rosoft.com...
| Hi, I need to "save" in a variable the event handler sub of a control's
| event, then perform some process, and finally "restore" the originally
saved
| event handler.
|
| Example in pseudo-code:
|
| 1) Save cmbMyCombo's event handler for SelectedIndexCh ange event.
|
| 2) Assign a temporary event handler sub to cmbMyCombo's for its
| SelectedIndexCh ange event.
| AddHandler cmbMyCombo.Sele ctedIndexChange d, AddressOf
| cmbMyCombo_Sele ctedIndexChange d_Temporary
|
| 3) Do some processing...
|
| 4) Restore the previously-saved event handler sub for the
| SelectedIndexCh ange event to cmbMyCombo.
|
| How can this be accomplished? Thanks in advance.
|
| Regards,
|
| Rick
Jan 4 '06 #5
Thank you for the explanation and the links. The combobox in particular
doesn't expose its list of event handlers, so there seems to be no simple way
to accomplish that in VB.NET

Regards,

Rick
"Jay B. Harlow [MVP - Outlook]" wrote:
Richard,
In addition to the other comments:

| Hi, I need to "save" in a variable the event handler sub of a control's
| event, then perform some process, and finally "restore" the originally
saved
| event handler.
There may be multiple event handler subs for a single events, is there a
specific handler you want to save or do you want to save the entire list?

The "problem" is that the list of event handlers are not publicly available.
Different classes store the list differently. A number of framework classes
store the handlers in the Component.Event s member:

http://msdn2.microsoft.com/en-us/lib...US,VS.80).aspx

While the convention for VB classes is a hidden field named for the Event,
for example the MyValueChanged event keeps the list in the
MyValueChangeEv ent field.

VB 2005 can use Custom Events to store the list of event handlers in the
Component.Event s member.

http://www.panopticoncentral.net/arc...8/06/1545.aspx

Gaining access to this list for classes other then your own, is problematic
at best, in that how the list is stored is an implementation detail that
could change...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Richard Grant" <Ri**********@d iscussions.micr osoft.com> wrote in message
news:37******** *************** ***********@mic rosoft.com...
| Hi, I need to "save" in a variable the event handler sub of a control's
| event, then perform some process, and finally "restore" the originally
saved
| event handler.
|
| Example in pseudo-code:
|
| 1) Save cmbMyCombo's event handler for SelectedIndexCh ange event.
|
| 2) Assign a temporary event handler sub to cmbMyCombo's for its
| SelectedIndexCh ange event.
| AddHandler cmbMyCombo.Sele ctedIndexChange d, AddressOf
| cmbMyCombo_Sele ctedIndexChange d_Temporary
|
| 3) Do some processing...
|
| 4) Restore the previously-saved event handler sub for the
| SelectedIndexCh ange event to cmbMyCombo.
|
| How can this be accomplished? Thanks in advance.
|
| Regards,
|
| Rick

Jan 4 '06 #6

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

Similar topics

4
12553
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)"; document.getElementById('myelement') = new Function("myfnc(param1,param2,param3)");
18
2867
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...
7
7115
by: Dee | last post by:
I have 11 numeric fields on a form which are all inter related. When any field changes after update, all need recalculation. Each field has an after update event procedure. Each of which runs the same code in different Private Subs. Is there a way to point each private sub to just one subroutine, or do I need all of this duplicate code?
5
1612
by: Martin Hills | last post by:
Hi Wondered if anyone can help with a couple of small problems we are having. Firstly, how do we check if someone has hit the F1 within a TextBox field? Secondly, we are having problem with handling events. We have used the follwing code to track that a called screen
8
1782
by: jcrouse | last post by:
I am using the following code to trap errors in a sub routine: Try Executable code Catch ex As Exception Dim strInputE As String = Application.StartupPath & "\Error.txt" Dim srE As StreamWriter = File.AppendText(strInputE) srE.WriteLine(vbCr) srE.WriteLine(vbCr) srE.WriteLine(DateTime.Now)
3
3761
by: Brett | last post by:
I'm using a third part component in a certain app. The component has methods and events. I noticed one particular event was not firing after a while but it should have been. The problem was the "handles" part was missing. I didn't remove this that I know of. After putting this back in, the event started firing. Actually, the code inside...
3
1463
by: johncee | last post by:
Greetings, I created a base class that has a datagrid. I've made it generic as possible so that any derived classes pass some info to the base constructor (including a SQL select stmt) & through the base class, any db table can be displayed/maintained in the grid. I've made some of the base class' event-handling subs overridable and in...
1
2244
by: pob | last post by:
>From a form I have some code that calls 4 modules frmMain 1 mod 2 mod 3 mod 4 mod If mod 1 experiences an error the error handling works fine within mod 1 and writes out the error to a table, but the other modules still get
3
3079
by: Mark | last post by:
Hi All, I have wrote a sub to record events from within the database. A lot of these events are errors. The sub has the module name and function/sub name passed to it to record to the table. My problem is that a lot of the subs within the modules are quite large so haveing the module name and procedure name points me in the right direction...
0
7703
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...
0
7618
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...
0
7926
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. ...
1
7678
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...
0
6286
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...
1
5514
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...
0
3656
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...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2116
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.