Listbox GotFocus problem

[quote=309718:@Karen Atkocius]Possibly another way… Create a flag in the listbox, set it in CellGotFocus (orLostFocus?) and Check it in Listbox.GotFocus to decide what to do and unset it if it was set

  • Karen[/quote]
    I would do it this way. And make it a listbox subclass so you can share it between projects.

I’ve just amended my program (see link above). The problem should be fixed. Tab and Shift+Tab. Everything is done on keypress so its independent of mouse interaction. The window property ignoreFocus should be a property of your own ListBox control so nothing else has access to it.

I’ll take a look at this a bit later.

Sorry for the delay, I got sidetracked by a CCTV install because some git decided to steal £50+ worth of diesel from the Landy :frowning:

Here you go, a fully contained ListBox control that implements TAB and SHIFT+TAB correctly.

It raises a new event called GotFocusTAB and LostFocusTAB when focus is moved via TAB or SHIFT+TAB

Let me know if you find any problems with it, I have tested it in Windows and macOS (new vmware install).

MyListBoxTAB

Thanks Julian, I’ll have a look at this shortly. Since I’d already got this working after a fashion, I’ve moved on to higher priorities for the past few days, but hope to get back to this in the next day or two.

Thanks also to Tim, Karen and Langue, for the suggestions.

[quote=309718:@Karen Atkocius]Possibly another way… Create a flag in the listbox, set it in CellGotFocus (orLostFocus?) and Check it in Listbox.GotFocus to decide what to do and unset it if it was set

  • Karen[/quote]

That is not bullet proof. That is because if you are editing a cell, if say you click in a different TextField control so it gets teh focus, CellLostFocus Fires but ListBox LostFocus does not also fire … And IMO it should logically as the the ActiveCell is not an independent control (I guess I should create a feature request or bug report about this subtlety)

But there is a workaround (untried) that should work using a timer to see where the focus goes

The way to make it work is to subclass the listbox and create a new ListBox.LostFocus event (and new Listbox.Gotfocus, CellGotFocus, CellLostFocus events if you want to keep those hooks for other uses) and use a timer started in CellLostFocus.

In the subclass

  1. Create a Flag : IsEditing as Boolean

  2. A method to determine where the focus and to unset the flag if it’s not the list
    Sub CheckFocus(theTimer as timer)
    If NOT (me.TrueWindow.Focus Is ME) then isEditing = False
    End Focus

  3. In the original CellLostFocus call the New CellLostFocus if you want it
    In the original CellLostFocus create a single shot timer (or CallLater) and use add handler to make it’s action the CheckFocus method and start it

  4. In the original ListBoxGotFocus call the new CellGotFocus if you want it
    check isEditing to decide what to do then set it to False

Unless I missed something, that should always work.

  • Karen