Home All Groups Group Topic Archive Search About
Author
8 Apr 2005 12:57 PM
Nice Chap
TextBox.TextChanged Event fires even when the text is changed
programatically. How can I detect that the text has been changed by the user
and not changed programatically?

Thanks

Author
8 Apr 2005 1:01 PM
Peter Proost
Hi look at the

Keydown or keyup event

Greetz Peter


Show quoteHide quote
"Nice Chap" <NiceC***@PlasmaDyne.com> schreef in bericht
news:e8BWVqDPFHA.3076@tk2msftngp13.phx.gbl...
> TextBox.TextChanged Event fires even when the text is changed
> programatically. How can I detect that the text has been changed by the
user
> and not changed programatically?
>
> Thanks
>
>
Author
8 Apr 2005 3:17 PM
Don
Don't forget the MouseDown/MouseUp events, in case the user pastes text by
right-clicking and selecting Paste on the popup menu (if any).


Show quoteHide quote
"Peter Proost" <pproost@nospam.hotmail.com> wrote in message
news:%23gbvItDPFHA.3076@tk2msftngp13.phx.gbl...
> Hi look at the
>
> Keydown or keyup event
>
> Greetz Peter
>
>
> "Nice Chap" <NiceC***@PlasmaDyne.com> schreef in bericht
> news:e8BWVqDPFHA.3076@tk2msftngp13.phx.gbl...
> > TextBox.TextChanged Event fires even when the text is changed
> > programatically. How can I detect that the text has been changed by the
> user
> > and not changed programatically?
> >
> > Thanks
> >
> >
>
>
Author
8 Apr 2005 1:10 PM
Cor Ligthert
Nice Chap,

Two ways.
Set a Boolean switch to evaluate that in the event
or
delete the handler when you do it programmatically

When you do it programmatically (and set it (back) afterwards)

I hope this helps,

Cor
Author
8 Apr 2005 1:16 PM
Herfried K. Wagner [MVP]
"Nice Chap" <NiceC***@PlasmaDyne.com> schrieb:
> TextBox.TextChanged Event fires even when the text is changed
> programatically. How can I detect that the text has been changed by the
> user and not changed programatically?

You may want to set a flag (for example, by setting the control's 'Tag'
property) before changing the value programmatically and check this flag in
the 'TextChanged' event handler.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
8 Apr 2005 1:32 PM
Cor Ligthert
Herfried,

>You may want to set a flag (for example, by setting the control's 'Tag'
>property)

Is using that tag for that an idea from VBCom (I saw Larry once doing that),
I don't see the benefit from it.

However maybe can you explain that too me(serious)

Cor
Author
8 Apr 2005 1:50 PM
Herfried K. Wagner [MVP]
"Cor Ligthert" <notmyfirstn***@planet.nl> schrieb:
>>You may want to set a flag (for example, by setting the control's 'Tag'
>>property)
>
> Is using that tag for that an idea from VBCom (I saw Larry once doing
> that), I don't see the benefit from it.
>
> However maybe can you explain that too me(serious)

Using the 'Tag' property might be easier because you don't need any
additional private variables.  However, it's one of many possible solutions
and its up to personal preference whether to use 'Tag' or not.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
8 Apr 2005 2:05 PM
Cor Ligthert
Herfried,

I find (and found it forever) wrong to use datafields that have no
descriptive names only to save 1 machineword. (that forever was a while
after the time that I was using relays, however than we could not give that
relay a descriptive name). However it sounds for me a behaviour from that
time.

I hope you agree that.

Cor
Author
8 Apr 2005 4:44 PM
95isalive
Ok, I've read all of the other responses, but I have to ask: "Why do you have to tell it
to do anything."

Simply Dim a "global" variable as a string and then do this:

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles TextBox1.TextChanged

myvariable = TextBox1.Text

End Sub

it detects any changes.

Or is there something wrong with doing this.??


--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed..................
...............................with a computer

Show quoteHide quote
"Nice Chap" <NiceC***@PlasmaDyne.com> wrote in message
news:e8BWVqDPFHA.3076@tk2msftngp13.phx.gbl...
> TextBox.TextChanged Event fires even when the text is changed
> programatically. How can I detect that the text has been changed by the user
> and not changed programatically?
>
> Thanks
>
>
Author
8 Apr 2005 5:35 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"95isalive" <ad***@95isalive.com> schrieb;
> Ok, I've read all of the other responses, but I have to ask: "Why do you
> have to tell it
> to do anything."
>
> Simply Dim a "global" variable as a string and then do this:
>
> Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
> _
> System.EventArgs) Handles TextBox1.TextChanged
>
> myvariable = TextBox1.Text
>
> End Sub
>
> it detects any changes.
>
> Or is there something wrong with doing this.??


Well, the OP wants tol execute the code 'myvariable = TextBox1.Text' only if
the text has been changed by the user and not when it was changed
programmatically.

\\\
Private Sub TextBox1_TextChanged( _
    ByVal sender As Object, _
    ByVal e As EventArgs _
) Handles TextBox1.TextChanged
    If Not DirectCast(sender, Control).Tag Then
        ...
    End If
End Sub
..
..
..
With Me.TextBox1
    .Tag = True
    .Text = "Hello World!"
    .Tag = False
End With
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
8 Apr 2005 5:41 PM
Cor Ligthert
Or making it in my opinion as syntax nicer using Herfrieds sample

dim SwProramTextBox1Change as boolean
Private Sub TextBox1_TextChanged( _
    ByVal sender As Object, _
    ByVal e As EventArgs _
    Handles TextBox1.TextChanged
    If Not SwProgramTextBox1Change Then
       ...
    End If
SwProgramChange = False
End Sub
///
\\\
SwProgramTextbox1Change = True
MeTextBox1.Text = "Hello World!"
///

:-)

Cor
Author
8 Apr 2005 5:56 PM
Herfried K. Wagner [MVP]
Cor,

Show quoteHide quote
"Cor Ligthert" <notmyfirstn***@planet.nl> schrieb:
> Or making it in my opinion as syntax nicer using Herfrieds sample
>
> dim SwProramTextBox1Change as boolean
> Private Sub TextBox1_TextChanged( _
>    ByVal sender As Object, _
>    ByVal e As EventArgs _
>    Handles TextBox1.TextChanged
>    If Not SwProgramTextBox1Change Then
>       ...
>    End If
> SwProgramChange = False
> End Sub
> ///
> \\\
> SwProgramTextbox1Change = True
> MeTextBox1.Text = "Hello World!"
> ///

I thought about resetting the flag inside the 'TextChanged' event handler
too but then decided not to do that.  By letting the user reset the
property/flag manually consecutive changes of the textbox's content are
possible.

\\\
With Me.TextBox1
    .Tag = True
    For i = 1 To 20
        ...
        If ... Then
            .Text = ...
        End If
    Next i
    .Tag = False
End With
///

The code above will not execute the code in the 'TextChanged' event handler
even if the textbox' text is changed more than once.

Just my 2 Euro cents...

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
8 Apr 2005 6:20 PM
Cor Ligthert
Herfried,

My main thing is that using a Tag (just because it is there) for what it is
not created for is in my opinion not right. (You know it is friday evening
and you know what that means, so I don't go in discussion anymore)

I think you are right about the side effect what you wrote. However don't
shoot me at  the moment when I did understand you wrong.

:-))

Cor
Author
8 Apr 2005 6:38 PM
Herfried K. Wagner [MVP]
Cor,

"Cor Ligthert" <notmyfirstn***@planet.nl> schrieb:
> My main thing is that using a Tag (just because it is there) for what it
> is not created for is in my opinion not right. (You know it is friday
> evening and you know what that means, so I don't go in discussion anymore)

Mhm...  I don't think that the use of 'Tag' shown in my sample is that bad,
but as I already said, I accept that other people choose another solution.

Show quoteHide quote
> I think you are right about the side effect what you wrote. However don't
> shoot me at  the moment when I did understand you wrong.

:-)

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
3 Jul 2005 11:12 AM
anatoly nulman
*** Sent via Developersdex http://www.developersdex.com ***