Programmatically move to next tab stop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #1

    Programmatically move to next tab stop

    How do you programmaticall y shift focus to the next tab stop? i.e. I have a bunch of textboxes that all have their tab orders set in sequence. The user hits enter as they finish entering data in any of them, I want to programmaticall y move the user to the next textbox in the sequence.

    Right now I'm using sendkeys to send the tab character, but there's just something about it I don't like...it seems kind of hokey. Is there a managed function call that I've missed somewhere?

    Something of the style "Form1.Controls .NextControl.Se tFocus" (yes, I know this isn't a valid call, it was just an example)

    Any ideas? Is there any other way to do this other than SendKeys?

    It seems obvious that you grab the tab index of the current control, increment it to the next number, but then you need to grab the control that has tabstop marked as true and has the next tabindex. Is there an simple way of grabbing the list of tabstopped controls, or does this have to be achieved programmaticall y too?
    Last edited by balabaster; Mar 14 '08, 07:20 PM. Reason: Add clarification to question
  • VBWheaties
    New Member
    • Feb 2008
    • 145

    #2
    Dont think there is a native method.
    However, it was easy enough to write something.
    Just send in your controls tabindex and it will set focus to the next controls tabindex.
    Code:
        Public Sub NextControl(ByVal ctrlTabIndex As Integer)
            For Each ctrl As Control In Controls
                If (ctrl.TabIndex) = (ctrlTabIndex + 1) Then
                    ctrl.Focus()
                End If
            Next
        End Sub

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      There is.
      Take a look at:
      Code:
      this.SelectNextControl(TheCurrentControl,true,true,(either true or false),(either true or false));
      All controls have the SelectNextContr ol() function that takes a control as a starting point then either looks for the next or previous control by tabstop

      Comment

      • VBWheaties
        New Member
        • Feb 2008
        • 145

        #4
        Originally posted by Plater
        There is.
        Take a look at:
        Code:
        this.SelectNextControl(TheCurrentControl,true,true,(either true or false),(either true or false));
        All controls have the SelectNextContr ol() function that takes a control as a starting point then either looks for the next or previous control by tabstop
        hey now, why didnt i know that? see, now I know why I come here.

        Comment

        • balabaster
          Recognized Expert Contributor
          • Mar 2007
          • 798

          #5
          Originally posted by Plater
          There is.
          Take a look at:
          Code:
          this.SelectNextControl(TheCurrentControl,true,true,(either true or false),(either true or false));
          All controls have the SelectNextContr ol() function that takes a control as a starting point then either looks for the next or previous control by tabstop
          I somehow knew that you would know the answer to that...I don't know why I don't have your direct email address :oP

          Comment

          • BAKUL TRIVEDI
            New Member
            • Sep 2013
            • 1

            #6
            Thanks Plater.
            Great. It is very much useful.

            Originally posted by Plater
            There is.
            Take a look at:
            Code:
            this.SelectNextControl(TheCurrentControl,true,true,(either true or false),(either true or false));
            All controls have the SelectNextContr ol() function that takes a control as a starting point then either looks for the next or previous control by tabstop

            Comment

            Working...