473,769 Members | 3,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it possible to disable events?

ORC
Hi,

Is it possible to disable an event like e.g. disabling:
private void textBox1_TextCh anged(object... .) ?

Thanks,
Ole
Nov 16 '05 #1
8 40303
Ole,

Unless the class offers some sort of management for this, there is no
standard mechanism to do it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"ORC" <or*@sol.dk> wrote in message
news:u0******** ******@TK2MSFTN GP15.phx.gbl...
Hi,

Is it possible to disable an event like e.g. disabling:
private void textBox1_TextCh anged(object... .) ?

Thanks,
Ole

Nov 16 '05 #2
Hi,

You can remove all event handlers and in this case, when the event is fired,
nothing will happen.
Why would you need to disable an event in the first place?

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"ORC" <or*@sol.dk> wrote in message
news:u0******** ******@TK2MSFTN GP15.phx.gbl...
Hi,

Is it possible to disable an event like e.g. disabling:
private void textBox1_TextCh anged(object... .) ?

Thanks,
Ole


Nov 16 '05 #3
Not possible. But, to achieve this effect, just don't hook any event
handlers to that event.
"ORC" <or*@sol.dk> wrote in message
news:u0******** ******@TK2MSFTN GP15.phx.gbl...
Hi,

Is it possible to disable an event like e.g. disabling:
private void textBox1_TextCh anged(object... .) ?

Thanks,
Ole

Nov 16 '05 #4
ORC
Thank you all for your input!
The reason for disabling events is that if e.g. all form controls are
initialized with a value from a database during load, it can be fatal if a
changed event fires and calculates new values from some of the controls that
hasn't yet finished updating - this is e.g. what I experied. However i found
something usefull, but it demands that one will have to do some work
himself:
EventHandler radioButtonEven t;
radioButtonEven t = new
System.EventHan dler(this.radio Button1_Checked Changed);

And now the event can be turned on and off at will like this:
enabling the event:
radioButton1.Ch eckedChanged += radioButtonEven t;
disabling the event:
radioButton1.Ch eckedChanged -= radioButtonEven t;

Thanks,
Ole
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote
in message news:Oy******** ******@TK2MSFTN GP15.phx.gbl...
Hi,

You can remove all event handlers and in this case, when the event is fired, nothing will happen.
Why would you need to disable an event in the first place?

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"ORC" <or*@sol.dk> wrote in message
news:u0******** ******@TK2MSFTN GP15.phx.gbl...
Hi,

Is it possible to disable an event like e.g. disabling:
private void textBox1_TextCh anged(object... .) ?

Thanks,
Ole

Nov 16 '05 #5
One thing you might want to try is the following:

You will find all the code to hook up the events in the generated code. You
can extract this code an put it into a subroutine that you can call in the
load after all the values required have been loaded.

One other thing is to set the controls to enabled = false. Then in the load
once the values are set enable all the controls. A disabled control will
not cause an event.

Lloyd Sheen

"ORC" <or*@sol.dk> wrote in message
news:O%******** ********@TK2MSF TNGP14.phx.gbl. ..
Thank you all for your input!
The reason for disabling events is that if e.g. all form controls are
initialized with a value from a database during load, it can be fatal if a
changed event fires and calculates new values from some of the controls
that
hasn't yet finished updating - this is e.g. what I experied. However i
found
something usefull, but it demands that one will have to do some work
himself:
EventHandler radioButtonEven t;
radioButtonEven t = new
System.EventHan dler(this.radio Button1_Checked Changed);

And now the event can be turned on and off at will like this:
enabling the event:
radioButton1.Ch eckedChanged += radioButtonEven t;
disabling the event:
radioButton1.Ch eckedChanged -= radioButtonEven t;

Thanks,
Ole
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote
in message news:Oy******** ******@TK2MSFTN GP15.phx.gbl...
Hi,

You can remove all event handlers and in this case, when the event is

fired,
nothing will happen.
Why would you need to disable an event in the first place?

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"ORC" <or*@sol.dk> wrote in message
news:u0******** ******@TK2MSFTN GP15.phx.gbl...
> Hi,
>
> Is it possible to disable an event like e.g. disabling:
> private void textBox1_TextCh anged(object... .) ?
>
> Thanks,
> Ole
>
>


Nov 16 '05 #6
ORC
A control that is disabled does indeed fire events! - the only solution is
to remove the eventhandler!

Thanks,
Ole

"Lloyd Sheen" <sq************ *******@tostops pamhotmail.com> wrote in message
news:yJ******** ************@ro gers.com...
One thing you might want to try is the following:

You will find all the code to hook up the events in the generated code. You can extract this code an put it into a subroutine that you can call in the
load after all the values required have been loaded.

One other thing is to set the controls to enabled = false. Then in the load once the values are set enable all the controls. A disabled control will
not cause an event.

Lloyd Sheen

"ORC" <or*@sol.dk> wrote in message
news:O%******** ********@TK2MSF TNGP14.phx.gbl. ..
Thank you all for your input!
The reason for disabling events is that if e.g. all form controls are
initialized with a value from a database during load, it can be fatal if a changed event fires and calculates new values from some of the controls
that
hasn't yet finished updating - this is e.g. what I experied. However i
found
something usefull, but it demands that one will have to do some work
himself:
EventHandler radioButtonEven t;
radioButtonEven t = new
System.EventHan dler(this.radio Button1_Checked Changed);

And now the event can be turned on and off at will like this:
enabling the event:
radioButton1.Ch eckedChanged += radioButtonEven t;
disabling the event:
radioButton1.Ch eckedChanged -= radioButtonEven t;

Thanks,
Ole
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote in message news:Oy******** ******@TK2MSFTN GP15.phx.gbl...
Hi,

You can remove all event handlers and in this case, when the event is

fired,
nothing will happen.
Why would you need to disable an event in the first place?

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"ORC" <or*@sol.dk> wrote in message
news:u0******** ******@TK2MSFTN GP15.phx.gbl...
> Hi,
>
> Is it possible to disable an event like e.g. disabling:
> private void textBox1_TextCh anged(object... .) ?
>
> Thanks,
> Ole
>
>



Nov 16 '05 #7
There is another solution that I use which, while it's less elegant,
is easy to understand, implement, and maintain, which makes it a
winner in my books.

Simply create a private bool flag in your form:

private bool populatingDispl ay = false;

Then inside each event handler you say:

private void txtMyTextBox_Te xtChanged(objec t sender, System.EventArg s
e)
{
if (!this.populati ngDisplay)
{
... react to event here ...
}
}

Now whenever you're mucking with the controls on the form and don't
want to react to the resulting events, just do this:

this.populating Display = true;
.... do whatever you like with the controls on the form ...
this.populating Display = false;

The events will still fire, but your bool flag will cause them all to
be ignored. (Yes, I hate bool flags, too, but this is one of those
cases in which all other solutions are uglier still.)
Nov 16 '05 #8
ORC
You're right - your solution is a lot easier to understand and maintain -
Thanks, I will use that instead!

Ole
"Bruce Wood" <br*******@cana da.com> wrote in message
news:a6******** *************** ***@posting.goo gle.com...
There is another solution that I use which, while it's less elegant,
is easy to understand, implement, and maintain, which makes it a
winner in my books.

Simply create a private bool flag in your form:

private bool populatingDispl ay = false;

Then inside each event handler you say:

private void txtMyTextBox_Te xtChanged(objec t sender, System.EventArg s
e)
{
if (!this.populati ngDisplay)
{
... react to event here ...
}
}

Now whenever you're mucking with the controls on the form and don't
want to react to the resulting events, just do this:

this.populating Display = true;
... do whatever you like with the controls on the form ...
this.populating Display = false;

The events will still fire, but your bool flag will cause them all to
be ignored. (Yes, I hate bool flags, too, but this is one of those
cases in which all other solutions are uglier still.)

Nov 16 '05 #9

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

Similar topics

2
5767
by: Dw70 | last post by:
I need write simple program with work in background and have only one function when it is run F1 I disable and when I pres for example ctrl+k it (program is terminate) maybe somebody have similar program or part of code I don't know how get signal F1 pressing and neutralize it?
7
23100
by: Scott Emick | last post by:
How can I disable events for the controls on a form? I tried setting the form's enable property to false, but that doesn't stop events from firing on its controls. I need to temporarily disable a form and load values into controls without any events firing, then re-enable the form. -- Scott Emick Web Programmer
4
3125
by: Chris | last post by:
I have an asp.net page say page1.aspx. The form in html code is <form id = "Form1"> And i want to disable all the fields of the form after some code steps. I had created a javascript funct: function disable() { alert("Forms length is :" + Form1.length); for (i = 0; i < Form1.length; i++) { var formElement = Form1.elements;
2
9152
by: bartlomiej.szafraniec | last post by:
Hi! I'm trying to implement custom button. But I don't want to extend Button class. I want to extend Control class. I want to implement Enable disable functionality. But unfortunatly when control is in Enable = false state the on click event is not called but that event is passed to parent object. How to convince my custom button class not to pass Click events to parent classes when my class is in Disabled state?
4
16861
by: Marc Solé | last post by:
Hello everybody, I have a little "problem". I have a DataGridView that is loaded automatically by code sometimes, and manually by the user other times. When the user introduces data in the DataGridView, there are some events that control the introduced data for any errors the user can do. That's OK. But when the data is loaded automatically, it is supposed that this data is
4
6630
by: Jon Slaughter | last post by:
Is there any method to temporarily disable focus changing?(I assume only method is tab or mouse?) This problem has been tieing me up for a while and nothing seems to work. The only thing that I *know* will work is to disable all tab stops on all controls. This brute force method doesn't seem like a good idea though. What I wanted to do was take control the control enter/leave and mouse enter/leave and "switch back" the focus when it is...
2
13495
by: SJ | last post by:
Dear Friends, I want to temporaraly disable events from my page. However, I cant seem to get it to work. It will show my disables message, but then it goes ahead and does the action I was trying to do (like clicking on a link). Here is the code, any ideas? ----- function disableEvents() {
10
8094
by: Gary Jefferson | last post by:
Suppose I have 3 modules that belong to a project, 'A', 'A.a' and 'B', and each module has its own logger, created with: module1logger = logging.getLogger('project.A') and module2logger = logging.getLogger('project.A.a') and
3
2874
pragathik
by: pragathik | last post by:
hi, below is my code <html> <body> <div> //HTML goes here with events like onclick,onchange </div>
0
9579
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
10035
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
9984
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
9851
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
8863
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
7403
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
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
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
3556
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.