Treeview Control will not set focus

mike72384

New Member
Joined
Aug 18, 2014
Messages
12
I have a form with many controls on it and the main one is a treeview. I have some code that brings up another form for the user to give some information and then run some simple code on the treeview, but the problem is when the code is ending and I ask it to set the focus to the treeview. I get no error, but when I run the routine the treeview somehow losses focus. VBA says it has the focus (checked with with the line debug.print UF1.activecontrol.name) but you cannot see a selected node, and the keyboard input is not going into the control. It seems to go nowhere. Also, strangely the exact same routine from a command button on the form works with no set focus issues. The issue is when running the code from a keydown event with "F2" or keycode 113 being the key to trigger the command. This is not a huge deal as I can easily just click inside the treeview and get the focus back, but I really like the functionality of not having to use the mouse if possible, and this just seems like something is going weirdly wrong here. Thanks for any help!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,215,754
Messages
6,126,680
Members
449,328
Latest member
easperhe29

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top