Re: delaying TextBox.TextChanged event

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Dan Bass (danielbass)
Date: 12/08/04


Date: Wed, 8 Dec 2004 09:12:12 -0000

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" <vonchi_m@yahoo.com> wrote in message
news:unJRceK3EHA.2600@TK2MSFTNGP09.phx.gbl...
> I'm trying to some dynamic searching to my windows Form so I added code in
> my TextBox.TextChanged 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.
>
>



Relevant Pages

  • RE: Cant browse without typing "http://"
    ... 30-second delay (little "flashlight" searching). ... It's like if you don't prepend the ... > home using an HP 2500 series printer. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: A moving flashlight pops up when I click on "My Computer"
    ... "lvee" wrote: ... searching for files. ... If it's always a long delay (more than a few ... in my opinion) it can mean that you, ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Implementing delays while thread is running
    ... MSDN says of the Security Descriptor in CreateWaitableTimer (& ... the timer object gets a default security ... So you could implement a delay with. ... the device has received and acted upon the command. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Implementing delays while thread is running
    ... MSDN says of the Security Descriptor in CreateWaitableTimer (& ... the timer object gets a default security ... WaitTimerHnd: THandle; ... I made that into a procedure and it seemed to work fine as a short delay in the main thread. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Need a little help
    ... Sorry for the delay in answering. ... I tried moving what I could to another ... So I ended up searching for data ... recovery tools. ...
    (microsoft.public.windowsxp.help_and_support)