|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Detecting textchanged event when user initiates itI 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 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 Show quoteHide quote "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 > > > Jerry Spence1 wrote:
> I want to fire an event when the user changes text, but I don't want to fire If you have the code that changes the text centralized, you can remove > 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 > > 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.
Show quote
Hide quote
"Chris" <no@spam.com> wrote in message Thanks Chris - I might as well have a boolean which I set to True before news:uVQYn6d%23GHA.1196@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. 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 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: Show quoteHide quote > 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 > > 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 Show quoteHide quote > 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 > 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: Show quoteHide quote > 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 >> > > 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. -- Show quoteHide quoteDennis 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 > >> > > > > >
Adding Lines to Access Database
Merging two VB.NET projects how to put two textboxes under each other? Asynchronous Socket Server Question where should the client app write the xml file to? Creating a new database with limits using SMO the find in a dataview??? Communicate with parallel port via web interphace Starting field on a form disappearing control |
|||||||||||||||||||||||