Tip

Tips from ITKnowledge Exchange VB.Net - Control.SetFocus

Back in the "old days" of VB6, Me.txtBox.SetFocus would give the text box of interest the focus. I'm in the process of learning VB.Net and this simple task appears to have changed. For the moment I'm using VB 2005 Express, I don't know if this matters, but I don't see a method to set the focus in code.

Any thoughts?

Thanks,

Tony

Highlighted replies from CharlesJC and irarainey

Tony: In VB.Net(2003) object.Focus() does the trick. It should be the same if not very similar in VB2005. - CharlesJC

Tony: From the help file: The following code example sets focus to the specified Control, if it can receive focus.

Public Sub ControlSetFocus(control As Control)
' Set focus to the control, if it can receive focus.
If control.CanFocus Then
control.Focus()
End If
End Sub

-irarainey

For more go to ITKnowledge Exchange [Reg Req]

This was first published in April 2006

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.