473,624 Members | 2,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

delaying TextBox.TextCha nged event

VMI
I'm trying to some dynamic searching to my windows Form so I added code in
my TextBox.TextCha nged so that, after every text change, a search is done to
a datatable. So if I want to type the string "Memphis", it'll do a search
(and display) all the items after the user types "M", then another search
(of "Me") when the user types "e", another search of "Mem" after "M", and so
on. The problem is that there's so much data in the table that each one of
these searches is very slow, and I can't use a primary key because it
searches in all columns (there's three).
Is there any way that I can delay the TextChange so it only executes if the
user doesn't type anything for, say, a second? Or is there any way I can do
this?

Thanks.
Nov 16 '05 #1
2 18129
One idea would be to have a timer object on the form set to the time you
want to the delay to be.

From here you could reset the timer everytime a valid key is pressed,
changing the value of your textbox. If the event of the timer fires, and you
have some text then I'd advise starting another thread to populate your
datatable.

You need to be careful of things like, what happens when you press a key
while the thread is busy populating the data table... clearly the thread
will have to be aborted before the new one can start, otherwise you'll have
two threads trying to populate the same datatable.

If you want to read up on multithreading, Jon Skeet's got a good article on
it:
http://www.yoda.arachsys.com/csharp/threads/

A complete alternative to all this is scrap the idea of searching after each
key press, even with a delay, and having a find button. This method holds
more weight, especially since you have a large dataset with no efficient way
of searching it.

Just hallow if you need any help.

"VMI" <vo******@yahoo .com> wrote in message
news:un******** ******@TK2MSFTN GP09.phx.gbl...
I'm trying to some dynamic searching to my windows Form so I added code in
my TextBox.TextCha nged so that, after every text change, a search is done
to a datatable. So if I want to type the string "Memphis", it'll do a
search (and display) all the items after the user types "M", then another
search (of "Me") when the user types "e", another search of "Mem" after
"M", and so on. The problem is that there's so much data in the table
that each one of these searches is very slow, and I can't use a primary
key because it searches in all columns (there's three).
Is there any way that I can delay the TextChange so it only executes if
the user doesn't type anything for, say, a second? Or is there any way I
can do this?

Thanks.

Nov 16 '05 #2
One suggestion is to use the System.Timers.T imer like so:

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

timer.AutoReset = false;
timer.Elapsed += new System.Timers.E lapsedEventHand ler(timer_Elaps ed);
}

System.Timers.T imer timer = new System.Timers.T imer( 500 );
private void textBox1_TextCh anged(object sender, System.EventArg s e)
{
timer.Stop();
timer.Start();
}

private void timer_Elapsed(o bject sender,
System.Timers.E lapsedEventArgs e)
{
Console.WriteLi ne( "Do something here." );
}

If you were getting really excited about it, you could write an
IExtenderProvid er component to so you could easily add this
functionality to any textbox...

Nov 16 '05 #3

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

Similar topics

1
4266
by: David Smith | last post by:
What I want to be able to do: A textbox is available that the user can enter information into. Specifically (for the purposes of this post), the user is asked to enter a number, and that number has an upper limit. I want to do validation on what the user enters as they type it in. I set up an event handler for KeyPress that restricts them from being able to enter non-numeric characters (only allowing numbers, decimal point, control...
5
2585
by: Vi | last post by:
Hello, I want to be able to reload a DropDownList when a TextBox changes its value. So I set the AutopostBack property of the TextBox to true and in the code behind I do something like: if(IsPostBack) { if( ((TextBox)sender).ID == "myTextBox" ) myDropDownList.DataBind(); }
4
1814
by: Craig G | last post by:
i have the following code for validating a textbox once a page posts, but the problem i am having is that the TextChanged event won't fire next time if the user does not change the value again One way round this is to clear the value but user's generally like to see the erroneous data any ideas? Cheers,
4
7386
by: MattB | last post by:
Hi. I'm working on an intranet application that requires a user to input information about themselves. I have a user control with a couple of textboxes that I want the user to enter their weight into. One is for Lbs and one is for kg and I'm using the OnTextChanged event to populate the other control if one is filled in (converting between kg and Lbs). It works, but when one TextBox is changed and it sets the other's value, the second...
3
4481
by: ton | last post by:
How can I detect that the user has modified the data on the page where several textboxes, checkboxes and dropdownlist exist. Ton
7
3071
by: Itar | last post by:
I'm having a problem supressing characters in a text box. I only want alpha numeric characters (no special chars). I can handle the TextBox_KeyPress event to supress the invalid characters when the user types them in, however that doesn't handle the user pasting invalid characters. I thought to use the MouseDown event but I couldn't figure out how to tell if the user is trying to paste or is copying the text. To paste the text the user...
10
3097
by: Dennis | last post by:
I have a simple form with one button and one text box. In the Form, I create an array list to track the events by adding a descriptive string item to the arraylist in each event. I first Click on the Button then Click on the TextBox and enter an "a" then click on the Button again. The following is what I get for the event tracking Arraylist: but - GotFocus but - Clicked but - LostFocus txt - Changed
3
2178
by: DotNetNewbie | last post by:
I am reading the book Teach Yourself Microsoft Visual Basic .Net 2003 in 21 Days. I am having trouble getting one of the exercises to work at the end of day 4. Exercises: 1. Create a new multiple-form application that displays two forms when it starts, each with a text box. Add code to each text box’s TextChanged event (this is the
4
29800
by: Jason Huang | last post by:
Hi, In my C# Windows form MyForm I have some TextBoxes. In these TextBoxes, we have to detect if the TextChanged event occurs, if there're changes in these TextBoxes, it will ask if we want to save the changes when we close the form. However, when I run the MyForm, it will fetch data from the system and put into TextBoxes, and this incurs the textchanged event. But I am thinking how do I make the TextBox's TextChanged know the
0
8182
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,...
0
8688
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
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...
0
7178
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
6115
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
4085
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
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2614
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
1
1800
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.