You can also try From.ActiveControl = ControlName.
Main Topics
Browse All TopicsMy WinForm has a treeview on the left side, clicking on a node determines what displays on the right hand side of the form using the treeview's afterselect event.
Right after a node is clicked, I want the editing cursor to display in the 2nd editable textbox on the right hand side of the screen, but my efforts to set focus to that textbox remain in vain. The focus remains on the treeview control no matter what code I put in its AfterSelect event. The Treeview control has tabstop = 0, but clicking on it apparently overrides that setting, which is understandable, but then no matter how many times my subsequent code says TextBox2.Focus(), the cursor will not move to it. I've even tried coding it in the MouseUp event of the Treeview control and still no dice.
However, if I physically press the Tab key right after the Treeview node is clicked, then everything assumes the initial state I am seeking.
So (assuming this is the only approach that will work) how do I programmatically send a Tab key to the form via VB.NET code?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This is very informative
http://www.pcreview.co.uk/
Thanks for the multiple prompt replies everyone, unfortunately only SendKeys fixed my problem.
"SendKeys" has a bad reputation in my shop due to its overuse and misuse in previous applications, so if there is a way to avoid using it and still accomplish my goal, I would be most interested, otherwise SendKeys response wins.
Try this:
Make a new vb.net winforms project.
Make a new form.
On the form place a treeview control and two text boxes.
Set TabOrder on the treeview control to false and accept the default tabs on the two text boxes.
Add a parent and child node to the treeview control.
In the Treeview's AfterSelect event, provide code to set the blinking cursor to the 2nd text box.
Run the project.
The form displays with the cursor blinking in the first text box.
Click a node of the treeview control.
What I want to happen is the blinking cursor appears in the 2nd text box.
Can anyone make that happen without using SendKeys?
I can't.
SendKey IS a bad idea since it is dependent on tab order and this can change for many reasons.
I`m not at my VS computer now, so I can`t recreate your senario, but I have an idea.
You can try setting the focus to the form holding both controls and then set the focus to the textbox
(using .select like I said before, not .focus)
Business Accounts
Answer for Membership
by: rettiseertPosted on 2009-10-06 at 15:31:29ID: 25510616
Hi
have you tried my.application.doevents() before focus() ?
if that doesnt work you can use
SendKeys.Send("{TAB}")