473,404 Members | 2,137 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,404 software developers and data experts.

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 SelectedIndexChange event.

2) Assign a temporary event handler sub to cmbMyCombo's for its
SelectedIndexChange event.
AddHandler cmbMyCombo.SelectedIndexChanged, AddressOf
cmbMyCombo_SelectedIndexChanged_Temporary

3) Do some processing...

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

How can this be accomplished? Thanks in advance.

Regards,

Rick
Jan 4 '06 #1
5 1870
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**********@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.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 SelectedIndexChange event.

2) Assign a temporary event handler sub to cmbMyCombo's for its
SelectedIndexChange event.
AddHandler cmbMyCombo.SelectedIndexChanged, AddressOf
cmbMyCombo_SelectedIndexChanged_Temporary

3) Do some processing...

4) Restore the previously-saved event handler sub for the
SelectedIndexChange 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**********@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.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 SelectedIndexChange event.

2) Assign a temporary event handler sub to cmbMyCombo's for its
SelectedIndexChange event.
AddHandler cmbMyCombo.SelectedIndexChanged, AddressOf
cmbMyCombo_SelectedIndexChanged_Temporary

3) Do some processing...

4) Restore the previously-saved event handler sub for the
SelectedIndexChange 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**********@discussions.microsoft.com> wrote in message
news:89**********************************@microsof t.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**********@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.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 SelectedIndexChange event.
>
> 2) Assign a temporary event handler sub to cmbMyCombo's for its
> SelectedIndexChange event.
> AddHandler cmbMyCombo.SelectedIndexChanged, AddressOf
> cmbMyCombo_SelectedIndexChanged_Temporary
>
> 3) Do some processing...
>
> 4) Restore the previously-saved event handler sub for the
> SelectedIndexChange 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.Events 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
MyValueChangeEvent field.

VB 2005 can use Custom Events to store the list of event handlers in the
Component.Events 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**********@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.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 SelectedIndexChange event.
|
| 2) Assign a temporary event handler sub to cmbMyCombo's for its
| SelectedIndexChange event.
| AddHandler cmbMyCombo.SelectedIndexChanged, AddressOf
| cmbMyCombo_SelectedIndexChanged_Temporary
|
| 3) Do some processing...
|
| 4) Restore the previously-saved event handler sub for the
| SelectedIndexChange 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.Events 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
MyValueChangeEvent field.

VB 2005 can use Custom Events to store the list of event handlers in the
Component.Events 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**********@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.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 SelectedIndexChange event.
|
| 2) Assign a temporary event handler sub to cmbMyCombo's for its
| SelectedIndexChange event.
| AddHandler cmbMyCombo.SelectedIndexChanged, AddressOf
| cmbMyCombo_SelectedIndexChanged_Temporary
|
| 3) Do some processing...
|
| 4) Restore the previously-saved event handler sub for the
| SelectedIndexChange 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
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...
7
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...
5
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...
8
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...
3
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...
3
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) &...
1
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.