I can’t get ClearFocus to work. I’m running MacOs.
I have a window with 2 listboxes and an entry field. I’m dragging and dropping between the listboxes. The entry field holds a name for the resulting list, it’s not a key just a name that can be changed.
Most times it won’t be changed so I’ve been trying to clear focus from it when the window opens. Whatever I do it still gets focus. At the bottom of the window open event I’ve tried ClearFocus, listbox1.setFocus, self.SetFocus and still the entry field has focus. I can tab out of it and that works but I don’t seem to be able to do it programmatically.
The problem is that users have complained that because the text is selected it’s too easy to inadvertently clear it.
Anything else I can try please.
Okay; so in the IDE, set the textfield.enabled to false, then in the activate event of the window make the textfield enabled.
I’m afraid that didn’t work either … the window still opens with the entry field text selected.
I’ve got a workaround … if the text field is cleared, and there is an old value than I can restore it and clear focus … but this all seems overly convoluted for something this straightforward.
TextField1.SelStart = 0 // ¨lace the caret at the beginning of the TextField
TextField1.SelLen = 0 // 0 selected characters
Please, verify the syntax.
This will not squash the bug, but unselect the TextField contents: no text cleared by error. I hope.
So I just had a play and read the Apple documents. I have a solution for you.
in the IDE set the enabled state to false.
Add a timer to the window with a period of 1 and mode as off, that enables the textfield. In the activate event of the Window, set timer’s mode to 1.
In reading the Apple documents, I get the impression that it’s designed to always have one control in focus when a window is first displayed.
I think your conclusion is correct. It seems a control must have focus during window open and if there’s an entry field it’s going to be that. Emile’s solution didn’t work, the entry field text was still selected although I explicitly set selstart and sellength to 0.
Your timer solution seems to have done the trick and the window is now behaving as I want. Thanks for that. I still think it’s a very convoluted way of doing something that should be very straightforward and the commands are there to do it.