473,396 Members | 1,997 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,396 software developers and data experts.

Detecting textchanged event when user initiates it

I want to fire an event when the user changes text, but I don't want to fire
it when the program changes the text. This must be a very common thing to
do, and I was wondering if there was a better event to use. I know there is
MouseClick but the user might not actually change anything. Any ideas?

-Jerry
Oct 27 '06 #1
7 2043
Hi Jerry,
This may not be what your looking for, but what I do is set a form level
Bool (isLoading) value to true when the program is making changes, and in the
TextChanged event I put this line at the top of the event:
if isLoading then exit sub

Hope this helps.
Michael

"Jerry Spence1" wrote:
I want to fire an event when the user changes text, but I don't want to fire
it when the program changes the text. This must be a very common thing to
do, and I was wondering if there was a better event to use. I know there is
MouseClick but the user might not actually change anything. Any ideas?

-Jerry
Oct 27 '06 #2
Jerry Spence1 wrote:
I want to fire an event when the user changes text, but I don't want to fire
it when the program changes the text. This must be a very common thing to
do, and I was wondering if there was a better event to use. I know there is
MouseClick but the user might not actually change anything. Any ideas?

-Jerry

If you have the code that changes the text centralized, you can remove
the handler to the textbox and then add it back on after you finished
your changes. This allows you to control when the event gets handled
and when it doesn't. You will need to remove the "Handles" tag from the
function and use addhandler & removehandler to do it instead.
Oct 27 '06 #3

"Chris" <no@spam.comwrote in message
news:uV****************@TK2MSFTNGP02.phx.gbl...
Jerry Spence1 wrote:
>I want to fire an event when the user changes text, but I don't want to
fire it when the program changes the text. This must be a very common
thing to do, and I was wondering if there was a better event to use. I
know there is MouseClick but the user might not actually change anything.
Any ideas?

-Jerry

If you have the code that changes the text centralized, you can remove the
handler to the textbox and then add it back on after you finished your
changes. This allows you to control when the event gets handled and when
it doesn't. You will need to remove the "Handles" tag from the function
and use addhandler & removehandler to do it instead.
Thanks Chris - I might as well have a boolean which I set to True before
changing the text by program and in the changetext event detect it and exit
the sub. This all seems very messy and I was wondering if there was another
property or method that might do it in a neater way.

-Jerry
Oct 27 '06 #4
Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Enter
'Save the original text
TextBox1.Tag = TextBox1.Text
End Sub

Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
'After editing
If CType(TextBox1.Tag, String) <TextBox1.Text Then
TextBox1_TextChanged(sender, New System.EventArgs)
End If
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs)
'The text has been changed ...
End Sub

Jerry Spence1 wrote:
I want to fire an event when the user changes text, but I don't want to fire
it when the program changes the text. This must be a very common thing to
do, and I was wondering if there was a better event to use. I know there is
MouseClick but the user might not actually change anything. Any ideas?

-Jerry

Oct 27 '06 #5
I picked up a bad habit in my VB3 days that I never got rid of. I set a form-level
variable that is named "IgnoreChanges" to True when I first initialize the
form's data and any other time I want to make changes myself. When I'm done
initializing, I set it to False. Then in the event handler, I only do my
special processing if the flag is set to False. There is probably a more
official way, such as checking for Me.Visible or another member like that.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
I want to fire an event when the user changes text, but I don't want
to fire it when the program changes the text. This must be a very
common thing to do, and I was wondering if there was a better event to
use. I know there is MouseClick but the user might not actually change
anything. Any ideas?

-Jerry

Oct 27 '06 #6
I don't think this is a bad habit - I call it an
EventFlowControlVariable - it does wonders in a lot of scenario's.

Tim Patrick wrote:
I picked up a bad habit in my VB3 days that I never got rid of. I set a
form-level variable that is named "IgnoreChanges" to True when I first
initialize the form's data and any other time I want to make changes
myself. When I'm done initializing, I set it to False. Then in the event
handler, I only do my special processing if the flag is set to False.
There is probably a more official way, such as checking for Me.Visible
or another member like that.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
>I want to fire an event when the user changes text, but I don't want
to fire it when the program changes the text. This must be a very
common thing to do, and I was wondering if there was a better event to
use. I know there is MouseClick but the user might not actually change
anything. Any ideas?

-Jerry

Oct 27 '06 #7
I would suggest the "removehandler" and the "addhandler" way to go. When you
are updating from the program, you can remove the handler then add it back in
thus no need to keep track of a form variable. When you have a lot of
different controls to update from different places in the program, it's much
easier to keep track using the handler. I used to use the form variable in
VB3, etc. but found the handler manipulation much easier to keep track of and
not much more code usually.
--
Dennis in Houston
"Theo Verweij" wrote:
I don't think this is a bad habit - I call it an
EventFlowControlVariable - it does wonders in a lot of scenario's.

Tim Patrick wrote:
I picked up a bad habit in my VB3 days that I never got rid of. I set a
form-level variable that is named "IgnoreChanges" to True when I first
initialize the form's data and any other time I want to make changes
myself. When I'm done initializing, I set it to False. Then in the event
handler, I only do my special processing if the flag is set to False.
There is probably a more official way, such as checking for Me.Visible
or another member like that.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
I want to fire an event when the user changes text, but I don't want
to fire it when the program changes the text. This must be a very
common thing to do, and I was wondering if there was a better event to
use. I know there is MouseClick but the user might not actually change
anything. Any ideas?

-Jerry
Oct 28 '06 #8

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

Similar topics

3
by: Fabrício de Novaes Kucinskis | last post by:
Hi all, I have a combobox control, in wich I put an autocomplete code. This code is in the TextChanged event, but when this event fires, the Text property isn't updated yet. For example, if...
4
by: Francesco | last post by:
Hi all, I am trying to make a UserControl with a TextBox in it. I have to publish the TextChanged event of the inner TextBox, but I have some trouble. If I declare : public event EventHandler...
2
by: Owin | last post by:
Hi all, I've created an User control. It's an extension of a textbox wich has some extra properties so that validation becomes a lot faster. The control wordks great if autopostback is on. When...
1
by: Samuel Chan | last post by:
I used the textchanged event of textbox and set the autopostback property to true. The textchanged event should fire when the content of the textbox is changed and user tab out of the textbox...
3
by: Woody Splawn | last post by:
We have a client server application where we would like to not show Save and Cancel buttons on a winform until the user has actually entered something into a textbox or combobox etc., and there is...
4
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...
3
by: Robert W. | last post by:
I'm new to ASP.net programming so excuse my ignorance if the following question seems overly simplistic. I've created a simple Login form with 3 primary WebControls: - A TextBox for the Username...
1
by: gonzosez | last post by:
I have an application that gets values from the registery and populates textboxes on a form. I have also created a sub using textchanged event. which prompts the user to save their changes. The...
1
by: jeeber | last post by:
I saw this on another thread (Francesco November 15th, 2005 UserControl.TextChanged) but I didn't see how to add to the discussion, so I'm just starting a new one and hope that people find it. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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,...

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.