How to scroll Firemonkey TListBox without capturing focus in its controls?

916 views Asked by At

I have a TListBox with controls in each item, such as TEdit, TComboBox, TSwitch, etc, aligned to the right. There are about 20 items in this list, so it extends beyond the screen, and thus user needs to scroll (by sliding finger) to get to the bottom.

The problem is that even in a quick gesture, if user swipes their finger initially on one of these controls, that control takes focus and the list doesn't scroll. Currently, the only way to scroll up or down is to swipe the finger on the left side of the list, where there aren't any controls. I could disable HitTest or CanFocus, but then that control would never get focus, even when the user wants to actually tap on it.

How can I allow user to swipe up or down on these controls to scroll the list without that control taking focus?

1

There are 1 answers

0
Robson Benedito On

I had the same issue.

To solve that insted using a TListBox I used a TVertScrollBox with a layout inside.

Each control is align to top and, to make it work, I needed a VKVertScrollBox from: https://github.com/DelphiWorlds/KastriFree/tree/master/Demos/VKVertScrollbox

Doing so you will have a scrollable list of components where you can swipe your finger down and see it moving.

Besides, to avoid the entering and getFocus on each component when swiping you can use a helper on each component to catch the movement by overriding MouseDown, MouseMove and MouseUp and prevent entering overriding doEnter (also overrited) if it is moving (catched on MouseMove method).