שתף באמצעות


Move to specific control using tab index

Question

Wednesday, March 18, 2009 8:32 AM

Hi There,

I want the solution to move to specific control by providing Tab index through coding. Is there any way that i send tab key through coding and cursor  move to or focus set to next control?

Thanks
Dalbir Singh

All replies (5)

Wednesday, March 18, 2009 9:55 AM ✅Answered | 2 votes

You can use  GetNextControl() Method ,which works on the taborder  of the controls within a control, to move the focus to the nextcontrol.

 Dim ctl As Control   
 
ctl = GetNextControl(ctl,True)  
 
ctl.Focus() 

 
if the last parameter of GetNextControl() Method is True then it searches in the forward order beginning with tab index = 0  else if it is false, it searches in reverse order beggining with the last tab order of the control.

Also you can use  SendKeys.SendWait(Chr(Keys.Tab)) to send tab key  to the form  without pressing the tab key.


Wednesday, March 18, 2009 8:55 AM | 2 votes

You can set the tab order programmatically use the following property

Control.TabIndex = 0
Control1.TabIndex = 1

Before doing that make the TabStop property of the controls to true.

For giving focus to a particular control you can use Control.Focus()

By default whenever you tab to a particular control it will get the current focus.
Thanks, A.m.a.L


Wednesday, March 18, 2009 1:12 PM

 

    Public Sub JumpToIndex(ByVal I As Integer)  
        For Each control As Control In Me.Controls  
            If control.TabIndex = I Then 
                control.Focus()  
            End If 
        Next 
    End Sub 
 
    ' sample of calling the subroutine
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
        JumpToIndex(2)  
    End Sub 

Try this sub routine.  Good luck


Wednesday, March 18, 2009 4:57 PM

I misread the question.  The above proposed answer by _asgar should do what you're looking for.


Thursday, March 19, 2009 10:58 AM

Thanks to All,

This is working.  Now i am able to move to next control. But the problem that i dont mention here and i think that by this way , problem may solve. But it is not working for my problem.

Actually, i am using Checkedlist box and web browser control in form. And there are some pdf and html files that i am showing in web browser according to selected item in listbox. I am doing difference between HTML and PDF by a property.If property is html then on selection of item  , web browser navigate to HTML File. In case of html , i am able to move on different items in list box by arrow keys.

But in case of PDF, i can not move to other item in list box by arrow keys. Because on selection of item, Control of Adobe to show pdf  capture the focus and keyboard.

That is why , i ask the above question. By this i move to another control and then set focus to CheckedListBox. But it is not working  properly.
By mean of properly is , Answer by _asger is working in debugging mode. But if i remove break point then it is not working.