wxTreeCtrl - SetFocus to TextCtrl

BlitzMax Forums/Brucey's Modules/wxTreeCtrl - SetFocus to TextCtrl

Retimer(Posted 2008) [#1]
Is something wrong with setfocus to a textctrl?

On treectrl; OnInit:
connectany(wxEVT_COMMAND_TREE_ITEM_ACTIVATED, Clicked) 



Function Clicked(_Event:wxEvent) 
	Local Tree:wxTreeCtrl = MyTree(_event.parent) 
	Local Obj:TPresetItem = TPresetItem(tree.GetItemData(Tree.GetSelection())) 
	If Obj Then
		txtFunctionCode.WriteText(Obj.Conversion) 
		Local F:Int, T:Int
		txtFunctionCode.GetSelection(F, T) 
		txtFunctionCode.SetSelection(f - (obj.Selection + 1), (f - (obj.Selection + 1)) + Obj.selection) 
		txtFunctionCode.SetFocus() 
	End If
End Function


It is writing the text, setting the selection, but not getting any keyboard focus. The focus remains on the Tree control, rather then switching to txtFunctionCode (TextCtrl).

Am I missing something or is this a bug?


DavidDC(Posted 2008) [#2]
My guess is that the click event on the tree node has already set the "let's put the focus on the node" code into action - which is overriding your attempt to divert the focus to a text control. Just a guess though!

I'd create a little sandbox test app and try intercepting the event a little lower down in the event queue by hooking into

Connect(GetId(),wxEVT_LEFT_DOWN, _OnLeftClick)

and then in _OnLeftClick doing a HitTest() on the mouse position to determine the selected node/item, making sure you don't skip the event. That way hopefully the click event won't propagate back up the control and your textctrl.SetFocus() will just work.

But then, it could be something as simple as an error in your txtFunctionCode class.


Brucey(Posted 2008) [#3]
You might want to try adding an event.Skip() in your event handler function. It's possible that it is still being handled after this function, which could be forcing focus to the treectrl.


Retimer(Posted 2008) [#4]
Nothing =(

I managed a workaround though, using a timer at 100ms, with oneshot enabled to set focus on the textctrl after the event is passed. It works good enough.

When double clicking on a tree control, it must activate 2 seperate events or something. One after _ACTIVATED, otherwise the event.skip you suggested should have worked.