Here is the situation:
I have 25 textboxes that are all handled by the same TextChanged event handler. My problem is, when I click my "Clear" button on the form, it clears all the textboxes and then fires my TextChanged event handler for each of the 25 textboxes, because their text is being "changed". I know this is how it is supposed to work, but it makes clearing my form take WAY too long! :)
Is there any way I can clear the event queue so it doesn't do the TextChanged event handler for all of the textboxes?
Or is there another way to get around this situation?
5 10816
have u try to ignore code if Textbox is empty like this? -
private void textBox1_TextChanged(object sender, EventArgs e)
-
{
-
if (((TextBox)sender).Text != "")
-
{
-
....
-
....
-
}
-
}
-
you are right, it does work, but it still clears very slowly because of the 25 calls to the eventhandler.
is there a way to "turn off" the event handler while i clear everything, and then turn it back on?
Ok, if u need to turn off/on event, u can write like this: -
private void btnTurnOffEvent_Click(object sender, EventArgs e)
-
{
-
this.textBox1.TextChanged -= new System.EventHandler(this.textBox1_TextChanged);
-
}
-
-
private void btnTurnOnEvent_Click(object sender, EventArgs e)
-
{
-
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
-
}
-
ahhh....perfect . thankyou!
NOW, is there a way to do this without writing this code for each individual textbox?....bec ause I have 35 text boxes..... :)
of course, u dont need to writing the code,
just copy, paste 34 times, then edit it :p
hehehe
u can use foreach to iterate all of controls.
this program assume all of textbox in a form must be processed.
if u only need some textbox,
put those in a container like Panel then use poperty Controls of panel -
private void btnTurnOffEvent_Click(object sender, EventArgs e)
-
{
-
foreach (Control ctrl in Controls)
-
{
-
if (ctrl is TextBox)
-
{
-
ctrl.TextChanged -= new System.EventHandler(this.textBox1_TextChanged);
-
}
-
}
-
}
-
-
private void btnTurnOnEvent_Click(object sender, EventArgs e)
-
{
-
foreach (Control ctrl in Controls)
-
{
-
if (ctrl is TextBox)
-
{
-
ctrl.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
-
}
-
}
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Graeme Matthew |
last post by:
Hi all
I just cannot seem to find any documentation that shows an example of using
the factory method Event() in threads. I have a thread pool and if there are
no jobs in a Queue I want them to wait for something to be inserted. When a
job is inserted I want to send an Event, the first thread that picks it up
runs with the job the rest wait for another insert Event.
I have been looking at some C, c++ implementations and some use a...
|
by: Dan |
last post by:
I've created a pocketpc app which has a startup form containing a listview.
The form creates an object which in turn creates a System.Threading.Timer.
It keeps track of the Timer state using a TimerState object similar to the
example in the System.Threading.Timer documentation. The method which
handles the timer events, among other things, periodically calls a method in
this TimerState object which raises an event to the startup form,...
|
by: Matt |
last post by:
Is it possible to clear the mail queue?
I'm developing a site on a remote host.
The code works fine and doesn't throw any errors. It was working correctly
up until a couple days ago. Then all mail stopped completely.
As I said, no errors--the mail doesn't arrive in the inbox.
So, is there a way to remotely clear that queue? The host's tech support
|
by: jack |
last post by:
Hi guys,
I am working on a project which requires an implementation of discrete
event simulation in C using linked lists. I would greatly appreciate if
someone could provide with some sources on how to approach DES. Please
help me out.
Thanks,
Jack
|
by: copx |
last post by:
How do you implement an event queue in C? The problem I had is that events
needed pointers to the objects they affect and I do not know any way to
check if pointers are actually valid in C. The main issue is that the
objects an event data structure points two might be removed before the event
is executed. The only solution I came up with was scanning the entire queue
each time an object was destroyed to remove all references to it. That was...
| |
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...
|
by: nt5515 |
last post by:
im trying to write a program that store a binary tree of possible events in an array. i need to be able to sort the the Events in the array based on the previous event that caused it by the time which they will occur. After the specific time has passed the event will be removed and all other events will be bumped up, all the while new events will be added to the end and sorted by their time.
Please Help
heres wot i've got so far, i've got...
|
by: Brad Walton |
last post by:
Hello. First post, but been doing a bit of reading here. I am working on a
project in Java, but decided to switch over to C# after seeing some of the
additional features I can get from C#. One of the big changes I want to make
is event-driven code (rather than the linear flow I had in Java). I have
spent a week or so searching Google, talking to a couple of programming
friends, and just chewing on it in my brain. I think I have an ok handle...
|
by: tb2500 |
last post by:
Dear all,
I want to create a Queue to add events that have been raised to, so later these events can be popped off the Queue stack and an appropriate Event Handler can be assigned. I wondered if this is actually possible?
How do I add events to a Queue?
So here's how it should go:
1. Raise an event ( no event handler for it exists yet )
2. Add this raised event to a Queue ( or a reference to it )
|
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...
|
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...
| |
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |