Re: Setting the correct tabindex

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Mike Eaton wrote:

Here's the problem: On condition A, I want input focus to go to a textbox on the panel when the form loads. On condition B, I want the input focus to go to the textbox that's on the form when the form loads. Seems pretty simple.

TabIndex only goes so far and, in this case, not far enough.
Youneed to forcibly move focus to another contorl, but you can't do that in Form_Load. The Form (and hence the Control) isn't visible, so won't accept focus - you have to wait until the Form appears, which is where the Activated event comes in.

Try this:

Private m_PendingFocus As Control = Nothing

Private Property PendingFocus() as Control
Get
Return m_PendingFocus
End Get
Set(Value as Control)
m_PendingFocus = Value
End Set
End Property

Private Sub Form_Activated( ... ) Handles MyBase.Activated
If Not (m_PendingFocus Is Nothing) Then
m_PendingFocus.Focus()
m_PendingFocus = Nothing
End If
End Sub

Private Sub Form_Load( ... ) Handles MyBase.Load
If ConditionA Then
Me.PendingFocus = TextBoxOnPanel
Else
' Do Nothing - the existing Tab Order will do
End If
End Sub

HTH,
Phill W.
.



Relevant Pages

  • Re: Textbox question
    ... Private Sub AddEventHandlers(ByVal ctrlContainer As Control) ... OrElse TypeOf ctrl Is ComboBox Then ... when you enter a textbox, and back to the original color when they leave. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Marsh...you were right!! HELP please!
    ... allowing full control over the use of the same - moving the focus from the combo ... box will again allow the textbox to regain its position over the combo box. ... Private Sub MyTextBox_Enter ... Bruce M. Thompson, Microsoft Access MVP ...
    (microsoft.public.access.formscoding)
  • Re: Creating an enhanced textbos.
    ... > If you use the ActiveX Control Interface Wizard and map ... > property to the usercontrol textbox, it will generate the following code: ... > 'Load property values from storage ... > Private Sub UserControl_WriteProperties ...
    (microsoft.public.vb.controls)
  • Re: control array question for VB.Net 2005
    ... Dim txt As TextBox ... AddHandler txt.Enter, AddressOf HandleEnter ... Private Sub HandleEnter ... Then, for each control in your array, use the AddHandler statement, pointing the Enter event of textbox to that procedure: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: control array question for VB.Net 2005
    ... Dim txt As TextBox ... AddHandler txt.Enter, AddressOf HandleEnter ... Private Sub HandleEnter ... Then, for each control in your array, use the AddHandler statement, ...
    (microsoft.public.dotnet.languages.vb)