Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SelectNextControl

Status
Not open for further replies.

Flupke

Programmer
Jun 26, 2002
94
BE
With SelectNextControl, you can only set focus to the next or the previous control.
Is it possible to set focus to the next or previous third or fourth or ..... control? Is there a parameter for SelectNextControl or another method to set the focus to a few controls further?

Many thanks and greetings from Brugge (Bruges - Belgium),

Michel
 
Code:
public function SelectNextControl(index as integer)
  dim iControl as integer
  for iControl = 0 to index-1
    SelectNextControl()
  next
end function

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Function needs to return something. Maybe you mean sub ?


-bclt
 
Ahh yeah, I was originally thinking of returning a reference to the current selected control, just fergot to throw it in there. Just change it to a sub and it'll work fine.

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
SelectNextControl() doesn't work on its own.

It has following parameters:

Me.SelectNextControl(CType(Me.ActiveControl, TextBox), True, True, True, True)

So, your solution "public function SelectNextControl(index as integer)" does not work as such.

How can I make that work?

Many thanks and greetings from Brugge (Bruges - Belgium),

Michel
 
A variable to remember whick control had the focus. As you click a button the focus goes to the button !

Code:
  [b]Dim HowLastHadFocus As Control[/b]


Suppose that you have 6 textboxes. This sub handles the gotFocus Event of all the textboxes. TextBox1 has tabindex 0, TextBox2 has tabindex 2 etc. You may add "listbox.GotFocus" and generaly all the controls you want to cycle.
Code:
Private Sub myTextBoxes_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus, _
TextBox2.GotFocus, _
TextBox3.GotFocus, _
TextBox4.GotFocus, _
TextBox5.GotFocus, _
TextBox6.GotFocus

  [COLOR=red]HowLastHadFocus = name_of_control[/color]    ' !!! 
  '  I can't remember how to get e.g. "TextBox4" :(
  '  I think with CType(...), not sure
End Sub


Then the last is the sub:

Code:
Private Sub SetTheFocus(ByVal Direction As String, ByVal Times As Int16)
[b]HowLastHadFocus.Focus()[/b]
If Direction.ToLower = "f" Then ' forward
  SendKeys.Send("{TAB " & Times & "}")
Else  ' backward
  SendKeys.Send("+{TAB " & Times & "}")
End If


At direction goes "f" or "F" for "TAB". For anything else
Shift+Tab is pressed.
At Times goes an integer. If it is 5 then tab OR Shift+Tab will be pressed (or better sent) 5 times.



Hope helps
-bclt
 
Code:
public shadows function SelectNextControl(index as integer) as boolean
  dim ReturnValue as boolean
  dim iControl as integer
  for iControl = 0 to index-1
    ReturnValue = Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
  next
end sub

Happy?

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top