Set the Focus to the ListBox, not the TextField?

In a window, I added a TextField to mirror the (first) Selected Line of a ListBox…

In Window.Open, LB.Open, and TF_Info.Open I set:

// Set the focus to the ListBox !
Self.Focus = LB

And the TextField still get the Focus at window open…

How can I achieve that ?

Maybe with a line just containing: LB.SetFocus() ?

I would not do this in an Opening Event. Better in a Timer which runs a few milliseconds after the window/container has opened. Just to make sure all objects are drawn, before i set the focus.

Beware on a Mac:

On the Mac you need Full Keyboard Access turned on in System Preferences (Keyboard->Shortcuts) in order to manually set focus to non-text controls.

You can also use the Activate event. Just add a property, as a boolean, so it works only on the first time the event is called.

Listboxes are covered by this “text controls”.

1 Like

change the tab order of the window ?

thanks for the awesome information.

1 Like

Listbox does not get focus that way.

Instead, use EditCellAt:

That will set the focus to that cell.

Focus and cell editing are different things.

Listbox.SetFocus will put the focus to the whole listbox; you can then use the up/down arrow to select to it, for example.

This start editing the cell (that’s more than setting the focus).

Only if you allow focus ring.

Yes, of course.

Did you actually try that? It doesn’t appear to work that way now, and I don’t remember a time when it ever did. Disabling the focus ring will not prevent cell editing. Can you upload a sample that shows that being the case? I’d consider that a bug in Xojo.

1 Like

Indeed without focus ring, one can still edit a cell.

However, setting focus to the entire listbox is only possible when the focus ring is enabled. I tried that to make sure.

At any rate, my first post was to answer Emile question. Apparently, he wants to set focus on a particular cell, which is achieved with EditCellAt.

I don’t believe you can have cell-specific focus without some additional work tracking and drawing the cell to be focused, especially by using EditCellAt. Unless I’m misunderstanding the problem. AllowFocusRing just turns off drawing of the focus ring, it doesn’t switch the ListBox to cell-specific focus.

EDIT: Re-reading the thread, Emile just wants to set the focus to the ListBox when opening, which doesn’t appear to be happening. Everything below post 5 is off-topic, misleading, and probably not helpful to him.

1 Like

This is not accurate. Here’s an example project:


1 Like

Since he did not care to participate in the discussion to clear any misunderstanding, we are all speaking for nothing.