Unable to Focus TextField that is inside a TreeView programatically

Hello everyone.

We are having a small issue with focusing a TextField that lives inside a TreeView. We created a custom TreeView inside a Custom Editor Window that each item contains some buttons and textfields. One of the things that we done is that when clicking on a button inside the TreeView Item, it will create a new item. This new item contains a TextField. So after the creation I am trying to ensure this TextField is focused, but nothing of the previous solutions found online seems to work. textField.Focus(), textField.ElementAt(0).Focus(), nothing. I checked that regardless what I try, the focusController.focusedElement is always on the TreeView element. Since the tab works, because after clicking on the button, the focus is on it, and after pressing tab a couple of times, I can select other elements in the proper order, but I can’t seem to be able to select, nor find the tab of the newly created TextField to be able to change the tabIndex. We are at a loss now.

Does any one have any idea how to focus items (textfield) inside a TreeView?

Thanks

Don’t know if this will help…
Could be that the button you clicked on keep on having the focus.
What could be the solution is to add a little delay or wait for the mouse to go really up.

So wait for the button event to really finish and unfocus the button?

Thanks for your suggestions @peterklaverlive

Your suggestion actually helped me understand what I was doing wrong.

After focusing, I was still creating another item on the tree, and that seemed to be losing the focus. Since the focus was kept in the button, I thought it wasn’t working at all.

So I moved the TextField.Focus() to the last line and it actually worked.

Thanks for your time and suggestion.

2 Likes