TextChanged

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nice Chap

    #1

    TextChanged

    TextBox.TextCha nged 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


  • Peter Proost

    #2
    Re: TextChanged

    Hi look at the

    Keydown or keyup event

    Greetz Peter


    "Nice Chap" <NiceChap@Plasm aDyne.com> schreef in bericht
    news:e8BWVqDPFH A.3076@tk2msftn gp13.phx.gbl...[color=blue]
    > TextBox.TextCha nged Event fires even when the text is changed
    > programatically . How can I detect that the text has been changed by the[/color]
    user[color=blue]
    > and not changed programatically ?
    >
    > Thanks
    >
    >[/color]


    Comment

    • Cor Ligthert

      #3
      Re: TextChanged

      Nice Chap,

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

      When you do it programmaticall y (and set it (back) afterwards)

      I hope this helps,

      Cor


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: TextChanged

        "Nice Chap" <NiceChap@Plasm aDyne.com> schrieb:[color=blue]
        > TextBox.TextCha nged 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 ?[/color]

        You may want to set a flag (for example, by setting the control's 'Tag'
        property) before changing the value programmaticall y 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/>

        Comment

        • Cor Ligthert

          #5
          Re: TextChanged

          Herfried,
          [color=blue]
          >You may want to set a flag (for example, by setting the control's 'Tag'
          >property)[/color]

          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


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: TextChanged

            "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=blue][color=green]
            >>You may want to set a flag (for example, by setting the control's 'Tag'
            >>property)[/color]
            >
            > 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)[/color]

            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/>

            Comment

            • Cor Ligthert

              #7
              Re: TextChanged

              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


              Comment

              • Don

                #8
                Re: TextChanged

                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).


                "Peter Proost" <pproost@nospam .hotmail.com> wrote in message
                news:%23gbvItDP FHA.3076@tk2msf tngp13.phx.gbl. ..[color=blue]
                > Hi look at the
                >
                > Keydown or keyup event
                >
                > Greetz Peter
                >
                >
                > "Nice Chap" <NiceChap@Plasm aDyne.com> schreef in bericht
                > news:e8BWVqDPFH A.3076@tk2msftn gp13.phx.gbl...[color=green]
                > > TextBox.TextCha nged Event fires even when the text is changed
                > > programatically . How can I detect that the text has been changed by the[/color]
                > user[color=green]
                > > and not changed programatically ?
                > >
                > > Thanks
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • 95isalive

                  #9
                  Re: TextChanged

                  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_TextCh anged(ByVal sender As System.Object, ByVal e As _
                  System.EventArg s) Handles TextBox1.TextCh anged

                  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

                  "Nice Chap" <NiceChap@Plasm aDyne.com> wrote in message
                  news:e8BWVqDPFH A.3076@tk2msftn gp13.phx.gbl...[color=blue]
                  > TextBox.TextCha nged 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
                  >
                  >[/color]


                  Comment

                  • Herfried K. Wagner [MVP]

                    #10
                    Re: TextChanged

                    "95isalive" <admin@95isaliv e.com> schrieb;[color=blue]
                    > 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_TextCh anged(ByVal sender As System.Object, ByVal e As
                    > _
                    > System.EventArg s) Handles TextBox1.TextCh anged
                    >
                    > myvariable = TextBox1.Text
                    >
                    > End Sub
                    >
                    > it detects any changes.
                    >
                    > Or is there something wrong with doing this.??[/color]


                    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
                    programmaticall y.

                    \\\
                    Private Sub TextBox1_TextCh anged( _
                    ByVal sender As Object, _
                    ByVal e As EventArgs _
                    ) Handles TextBox1.TextCh anged
                    If Not DirectCast(send er, 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/>

                    Comment

                    • Cor Ligthert

                      #11
                      Re: TextChanged

                      Or making it in my opinion as syntax nicer using Herfrieds sample

                      dim SwProramTextBox 1Change as boolean
                      Private Sub TextBox1_TextCh anged( _
                      ByVal sender As Object, _
                      ByVal e As EventArgs _
                      Handles TextBox1.TextCh anged
                      If Not SwProgramTextBo x1Change Then
                      ...
                      End If
                      SwProgramChange = False
                      End Sub
                      ///
                      \\\
                      SwProgramTextbo x1Change = True
                      MeTextBox1.Text = "Hello World!"
                      ///

                      :-)

                      Cor


                      Comment

                      • Herfried K. Wagner [MVP]

                        #12
                        Re: TextChanged

                        Cor,

                        "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=blue]
                        > Or making it in my opinion as syntax nicer using Herfrieds sample
                        >
                        > dim SwProramTextBox 1Change as boolean
                        > Private Sub TextBox1_TextCh anged( _
                        > ByVal sender As Object, _
                        > ByVal e As EventArgs _
                        > Handles TextBox1.TextCh anged
                        > If Not SwProgramTextBo x1Change Then
                        > ...
                        > End If
                        > SwProgramChange = False
                        > End Sub
                        > ///
                        > \\\
                        > SwProgramTextbo x1Change = True
                        > MeTextBox1.Text = "Hello World!"
                        > ///[/color]

                        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/>

                        Comment

                        • Cor Ligthert

                          #13
                          Re: TextChanged

                          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


                          Comment

                          • Herfried K. Wagner [MVP]

                            #14
                            Re: TextChanged

                            Cor,

                            "Cor Ligthert" <notmyfirstname @planet.nl> schrieb:[color=blue]
                            > 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)[/color]

                            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.
                            [color=blue]
                            > 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.[/color]

                            :-)

                            --
                            M S Herfried K. Wagner
                            M V P <URL:http://dotnet.mvps.org/>
                            V B <URL:http://classicvb.org/petition/>

                            Comment

                            • anatoly nulman

                              #15
                              Re: TextChanged





                              *** Sent via Developersdex http://www.developersdex.com ***

                              Comment

                              Working...