Synchronized ListBoxes


Synchronized ListBoxes

I have created a test app that has 2 ListBoxes where the ListBoxItems move with each other. It works but has an oddity.
If the right side ListBoxItem (lbi) is out of view when the corresponding left side lbi is selected then the right side lbi move into view at the top or bottom of the right side box, but not aligned with the left side lbi.

I can work with this in my app but is not user-friendly. Does anyone have any suggestions on avoiding an offset?

The pas code:
unit LBTest;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Controls.Presentation, FMX.Layouts, FMX.ListBox;

type
TForm1 = class(TForm)
lb1: TListBox;
pnl1: TPanel;
lb2: TListBox;
btn1: TButton;
procedure btn1Click(Sender: TObject);
procedure lb2Change(Sender: TObject);
procedure lb1Change(Sender: TObject);
procedure lb1MouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; var Handled: Boolean);
private
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.btn1Click(Sender: TObject);
var
id: Integer;
begin
for id :=1 to 25 do
begin
lb1.Items.AddObject(IntToStr(id) + ': Left', TObject(id));
lb2.Items.AddObject(IntToStr(Id) + ': Right', TObject(id));
end;
end;

procedure TForm1.lb1Change(Sender: TObject);
begin
lb2.ItemIndex := lb1.ItemIndex;
end;

procedure TForm1.lb1MouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; var Handled: Boolean);
begin
if WheelDelta <0 then
lb1.ItemIndex := lb1.ItemIndex +1
else
lb1.ItemIndex := lb1.ItemIndex -1;
lb2.ItemIndex := lb1.ItemIndex;
Handled := True;
end;

procedure TForm1.lb2Change(Sender: TObject);
begin
lb1.ItemIndex := lb2.ItemIndex;
end;

end.

Comments

  1. Lars Kruger I should also say that the test app will not work on Android 'cause of the TObject. The test app is for finding a way to make synchronize to work.

    ReplyDelete

Post a Comment