none
.focus command guide. need code RRS feed

  • Question

  • hi

    when i try to move one textbox1.leave event,  write command

    textbox2.focus

    when i saw in Debug it loop,  in debug yellow line come  on textbox2.focus than again go up and down.

     Private Sub TextBox1_Leave(sender As System.Object, e As System.EventArgs) Handles TextBox1.Leave
            TextBox2.Focus()
        End Sub
    where is problem in my code. how to solve it.


    MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

    Tuesday, December 10, 2019 9:35 PM

Answers

  • Maybe remove such Leave events, which seem inappropriate, and adjust Tab Index according to your needs. In order to see the order in Visual Studio 2019, go to menu, View, Tab Order. You can also click the numbers to change the order.

    • Marked as answer by muhammadanzar Monday, December 16, 2019 6:47 AM
    Wednesday, December 11, 2019 7:00 AM

All replies

  • Try

    Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
        ActiveControl = TextBox2
    End Sub


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, December 10, 2019 10:01 PM
    Moderator
  • thanks for reply

    i tried this code but problem not solved.   i saw one thing my 2 control tab index deference. like

    textbox1.text (tab index-1) leave event,(ActiveControl = TextBox2),create problem

    datagridview (tab index-2)

    textbox2.text(tab index-3

    textbox1.text (tab index-1) leave event,(ActiveControl = TextBox2),problem solve
    
    datagridview (tab index-3)
    
    textbox2.text(tab index-2) 

    but now current issue, i have many control in form,  move cursor according to my requirement.  some time,  move cursor with not follow tab index?

    How can i see the Tab index All Control easy?

    thanks



    MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

    Wednesday, December 11, 2019 1:18 AM
  • Hi,

    If you want Textbox to get focus, then using the following method is also a good choice.

        Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
            TextBox2.Select()
        End Sub

    If you just want the debug yellow line to go up and down again and again. You need to write other code later, instead of just writing this sentence.

    Hope it be helpful.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 11, 2019 1:49 AM
    Moderator
  • Hi

    *MAYBE* you have duplicated TAB INDEX values. For example, if you have a Button with TAB INDEX 22 and a TextBox with TAB INDEX 22 also, then when the Button is the ActiveControl, pressing the TAB KEY will skip the TextBox and go to the control with the next higher TAB INDEX.

    I am surprised that 2 or more controls may have the same TAB INDEX, but seems it is allowed.


    Regards Les, Livingston, Scotland

    Wednesday, December 11, 2019 3:22 AM
  • Maybe remove such Leave events, which seem inappropriate, and adjust Tab Index according to your needs. In order to see the order in Visual Studio 2019, go to menu, View, Tab Order. You can also click the numbers to change the order.

    • Marked as answer by muhammadanzar Monday, December 16, 2019 6:47 AM
    Wednesday, December 11, 2019 7:00 AM
  • Another option is handling this in the KeyDown event using SelectNextControl. Make sure to read the documentation as setting up the parameters can make or break this from working. Also note SelectNextControl returns a Boolean, true it worked, false it failed.

    If e.KeyCode = Keys.Tab Then
        e.Handled = True
        Me.SelectNextControl(DirectCast(sender, Control), True, True, True, True)
    End If


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, December 11, 2019 11:57 AM
    Moderator