Listbox - listindex sets focus

Setting the listindex of a listbox moves the cursor to the pointed row, and sets the focus to this listbox control.
Does anybody know a trick to move the cursor to another row without moving the cursor from whatever control to this listbox ?

Not always: only when the target (ListIndex) Row is visible (in the visible part of the Listbox); otherwise it does not display it.

I do not know, usually, this is what I want.

What about to save the Control that have the Focus (in the Window’s Class) before setting the LitIndex and set it back to the saved Control back

Line 1: get the current control’s focus
Line 2: change the Listbox.ListIndex
Line 3: set back the window focus to what was saved in line 1.

If you have a “flash”, you can trick the UI (before Line 1 and let it update itself after Line 3 ?

How to find out find out what is control the current focus is??

You have the description in the WIndow entry of the LR:
http://documentation.xojo.com/api/deprecated/window.html#window-focus

Enjoy !

Edit: the other question is how do I (simply) store an unknow type Control reference in a variable ?

The complex answer is: use IsA in a large If Then Else End If block (with all possible Controls that exists in that window).

i learn something new today. i always use setfocus for line 3 but never ever know i can do that

I discovered lately some other Window and focus related… type Window1.>tab> and Search them[FocusNext and FocusPrevious Methods].

You may try to use FocusPrevious first (and if this do not works, try IsA…).

Edit: remove typos…

Ah, thanks @Emile Schwarz for the hint to the Window.Focus property. Now I can obtain the handle of the control that has the focus at the moment a timer_action event fires.
Brings me to the next question: how can I set the focus back to the control with this handle without looping all controls ?

If Window.Focus returned a RectControl can’t you store that then call RectControl.SetFocus ?

Window1.FocusPrevious is certainly the correct answer (I hope so).

Nope !!

Yes ! This is it . Thanks,a lot for the simple stupid tip @JulianS . It’s so simple …

When you have the solution, but how hard when you are seeking one ! :wink:

It’s true. Sometimes you only need to explain what your problem is and the solution is around the corner.

Explaning the problem often leads to a solution.