Question on SelectAll

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wayne  Wengert

    Question on SelectAll

    In the GotFocus event for several text boxes I include code such as
    "txtMyTxtBox.Se lectAll". When I tab from textbox to textbox the text in the
    textbox that got focus is selected as expected but if I use the mouse to
    click on the textbox the text is not selected. I suspect this has something
    to do with the order in which the various events fire? In VB6 this worked.

    Does anyone have any suggestions regarding what is happening here and/or
    ways to get the text selected when a mouse is used for changing focus?

    Wayne


  • Hal Rosser

    #2
    Re: Question on SelectAll

    you should use the 'enter' event - not the gotfocus event

    "Wayne Wengert" <wayneDONTWANTS PAM@wengert.com > wrote in message
    news:OVu84VSjEH A.536@TK2MSFTNG P11.phx.gbl...[color=blue]
    > In the GotFocus event for several text boxes I include code such as
    > "txtMyTxtBox.Se lectAll". When I tab from textbox to textbox the text in[/color]
    the[color=blue]
    > textbox that got focus is selected as expected but if I use the mouse to
    > click on the textbox the text is not selected. I suspect this has[/color]
    something[color=blue]
    > to do with the order in which the various events fire? In VB6 this worked.
    >
    > Does anyone have any suggestions regarding what is happening here and/or
    > ways to get the text selected when a mouse is used for changing focus?
    >
    > Wayne
    >
    >[/color]


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004


    Comment

    • Wayne  Wengert

      #3
      Re: Question on SelectAll

      Hal;

      I wasn't even aware of that. Let me try you suggestion. BTW, is LostFocus
      still the best to use when leaving an object (I want to reset the background
      color)

      Wayne

      "Hal Rosser" <hmrosser@bells outh.net> wrote in message
      news:_i5Yc.5250 5$0o5.51766@big news1.bellsouth .net...[color=blue]
      > you should use the 'enter' event - not the gotfocus event
      >
      > "Wayne Wengert" <wayneDONTWANTS PAM@wengert.com > wrote in message
      > news:OVu84VSjEH A.536@TK2MSFTNG P11.phx.gbl...[color=green]
      > > In the GotFocus event for several text boxes I include code such as
      > > "txtMyTxtBox.Se lectAll". When I tab from textbox to textbox the text in[/color]
      > the[color=green]
      > > textbox that got focus is selected as expected but if I use the mouse to
      > > click on the textbox the text is not selected. I suspect this has[/color]
      > something[color=green]
      > > to do with the order in which the various events fire? In VB6 this[/color][/color]
      worked.[color=blue][color=green]
      > >
      > > Does anyone have any suggestions regarding what is happening here and/or
      > > ways to get the text selected when a mouse is used for changing focus?
      > >
      > > Wayne
      > >
      > >[/color]
      >
      >
      > ---
      > Outgoing mail is certified Virus Free.
      > Checked by AVG anti-virus system (http://www.grisoft.com).
      > Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004
      >
      >[/color]


      Comment

      • Wayne  Wengert

        #4
        Re: Question on SelectAll

        Hal;

        I tried using the enter event as you suggested (and I do see that there is a
        corresponding Leave event) but although the event fires and the background
        color of the textbox changes, it still does not select the text. In the code
        below, the SetBackground sub simply changes the textbox's background color -
        to help the user see what object has focus. If I walk through the code I can
        see that the SelectAll is being executed but the text does not end up
        selected - I'll do some digging about the enter event.

        Private Sub txtAssocContact LastName_Enter( ByVal sender As Object, ByVal e As
        System.EventArg s) Handles txtAssocContact LastName.Enter

        SetBackground()

        txtAssocContact LastName.Select All()

        End Sub



        Wayne

        "Hal Rosser" <hmrosser@bells outh.net> wrote in message
        news:_i5Yc.5250 5$0o5.51766@big news1.bellsouth .net...[color=blue]
        > you should use the 'enter' event - not the gotfocus event
        >
        > "Wayne Wengert" <wayneDONTWANTS PAM@wengert.com > wrote in message
        > news:OVu84VSjEH A.536@TK2MSFTNG P11.phx.gbl...[color=green]
        > > In the GotFocus event for several text boxes I include code such as
        > > "txtMyTxtBox.Se lectAll". When I tab from textbox to textbox the text in[/color]
        > the[color=green]
        > > textbox that got focus is selected as expected but if I use the mouse to
        > > click on the textbox the text is not selected. I suspect this has[/color]
        > something[color=green]
        > > to do with the order in which the various events fire? In VB6 this[/color][/color]
        worked.[color=blue][color=green]
        > >
        > > Does anyone have any suggestions regarding what is happening here and/or
        > > ways to get the text selected when a mouse is used for changing focus?
        > >
        > > Wayne
        > >
        > >[/color]
        >
        >
        > ---
        > Outgoing mail is certified Virus Free.
        > Checked by AVG anti-virus system (http://www.grisoft.com).
        > Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004
        >
        >[/color]


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Question on SelectAll

          * "Wayne Wengert" <wayneDONTWANTS PAM@wengert.com > scripsit:[color=blue]
          > I wasn't even aware of that. Let me try you suggestion. BTW, is LostFocus
          > still the best to use when leaving an object (I want to reset the background
          > color)[/color]

          That's the best way, IMO. You can use the 'Leave' event too. Be sure
          you read and understood the docs on both events.

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

          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Question on SelectAll

            * "Hal Rosser" <hmrosser@bells outh.net> scripsit:[color=blue]
            > you should use the 'enter' event - not the gotfocus event[/color]

            This doesn't make any difference, and there is IMHO no reason to prefer
            'Enter' over 'GotFocus'.

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

            Comment

            • Wayne  Wengert

              #7
              Re: Question on SelectAll

              I looked up the events and, as suggested, either should work. According to
              the Help, the events fire in the following sequence:

              ============= From Help Info ===============
              When you change the focus by using the keyboard (TAB, SHIFT+TAB, and so on),
              by calling the Select or SelectNextContr ol methods, or by setting the
              ContainerContro l.ActiveControl property to the current form, focus events
              occur in the following order:

              Enter
              GotFocus
              Leave
              Validating
              Validated
              LostFocus
              When you change the focus by using the mouse or by calling the Focus method,
              focus events occur in the following order:

              Enter
              GotFocus
              LostFocus
              Leave
              Validating
              Validated
              =============== =============== ============

              In my case, neither Enter nor GotFocus select the text - Weird?

              Wayne


              "Wayne Wengert" <wayneDONTWANTS PAM@wengert.com > wrote in message
              news:OVu84VSjEH A.536@TK2MSFTNG P11.phx.gbl...[color=blue]
              > In the GotFocus event for several text boxes I include code such as
              > "txtMyTxtBox.Se lectAll". When I tab from textbox to textbox the text in[/color]
              the[color=blue]
              > textbox that got focus is selected as expected but if I use the mouse to
              > click on the textbox the text is not selected. I suspect this has[/color]
              something[color=blue]
              > to do with the order in which the various events fire? In VB6 this worked.
              >
              > Does anyone have any suggestions regarding what is happening here and/or
              > ways to get the text selected when a mouse is used for changing focus?
              >
              > Wayne
              >
              >[/color]


              Comment

              • Hal Rosser

                #8
                Re: Question on SelectAll

                MAybe so - I was just going by MSDN recommendations to use 'Enter' over
                GotFocus

                Maybe if he adds 'selectall() ' to the click event as well ?? - would that
                solve the OP's problem ?


                "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                news:2pc9bkFjcf upU3@uni-berlin.de...[color=blue]
                > * "Hal Rosser" <hmrosser@bells outh.net> scripsit:[color=green]
                > > you should use the 'enter' event - not the gotfocus event[/color]
                >
                > This doesn't make any difference, and there is IMHO no reason to prefer
                > 'Enter' over 'GotFocus'.
                >
                > --
                > M S Herfried K. Wagner
                > M V P <URL:http://dotnet.mvps.org/>
                > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>[/color]


                ---
                Outgoing mail is certified Virus Free.
                Checked by AVG anti-virus system (http://www.grisoft.com).
                Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004


                Comment

                • Herfried K. Wagner [MVP]

                  #9
                  Re: Question on SelectAll

                  * "Hal Rosser" <hmrosser@bells outh.net> scripsit:[color=blue]
                  > MAybe so - I was just going by MSDN recommendations to use 'Enter' over
                  > GotFocus[/color]

                  OK, you are right. There is a note in the docs.

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

                  Comment

                  • Hal Rosser

                    #10
                    Re: Question on SelectAll

                    For some reason - this will work sometimes: do focus() statement first
                    just before the SelectAll() statement, do a Focus() statement
                    [color=blue][color=green]
                    > >
                    > > Does anyone have any suggestions regarding what is happening here and/or
                    > > ways to get the text selected when a mouse is used for changing focus?
                    > >
                    > > Wayne
                    > >
                    > >[/color]
                    >
                    >[/color]


                    ---
                    Outgoing mail is certified Virus Free.
                    Checked by AVG anti-virus system (http://www.grisoft.com).
                    Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004


                    Comment

                    • Wayne  Wengert

                      #11
                      Re: Question on SelectAll

                      Hal,

                      Thanks for that idea. It didn't work in my case. FYI, if I add another
                      SelectAll in the click event that does work - but I have over 25 forms, some
                      with 20+ text boxes - that is a lot of extra code. Do you know if this is
                      fixed in VSNET 2005?

                      Wayne

                      "Hal Rosser" <hmrosser@bells outh.net> wrote in message
                      news:1sbYc.5559 6$0o5.50186@big news1.bellsouth .net...[color=blue]
                      > For some reason - this will work sometimes: do focus() statement first
                      > just before the SelectAll() statement, do a Focus() statement
                      >[color=green][color=darkred]
                      > > >
                      > > > Does anyone have any suggestions regarding what is happening here[/color][/color][/color]
                      and/or[color=blue][color=green][color=darkred]
                      > > > ways to get the text selected when a mouse is used for changing focus?
                      > > >
                      > > > Wayne
                      > > >
                      > > >[/color]
                      > >
                      > >[/color]
                      >
                      >
                      > ---
                      > Outgoing mail is certified Virus Free.
                      > Checked by AVG anti-virus system (http://www.grisoft.com).
                      > Version: 6.0.744 / Virus Database: 496 - Release Date: 8/24/2004
                      >
                      >[/color]


                      Comment

                      Working...