Why Listbox items change order position and colour background after do scrolling in Firemonkey?

  

I am developing a Multi-Device Application in Firemonkey where Main class has a ListBox component with some items. Each of these items has the same custom style.

My problem is when I have so many items in the ListBox and I have to do scroll vertical to see the rest of items. In this case, the ListBox has a strange behaviour and when I do scroll up after doing scroll down the item’s components (a button for example) have changed his background colour and the items have changed his order inside ListBox.

For example, if I had:

Item 1

Item 2

Item 3

after I do scroll I have:

Item 2

Item 3

Item 1

This change is random. Each time is different.

Real example (process steps):

Load the Main class where is ListBox.

Do vertical scrolling down to see the rest of items.
Do vertical scrolling upward to return to the top of the list.

The items have changed position in the ListBox and the button (component of each item) changes its background color.

Why I have this behaviour in the ListBox??

How I can solve it and the ListBox do not change items order neither background colour of his components?

I do not know if there is any property to block items inside ListBox or similar …

EDIT

This is the code to create and initialize the ListBox items:

procedure TRooms_Form.FormCreate(Sender: TObject);
var

begin
i := 0;
while i < numItems do begin
//Create ListBox item
item := TListBoxItem.Create(nil);
item.Parent := myListBox;
item.StyleLookup := ‘styleLBox’;
//Number
itemNumber := item.FindStyleResource(‘btt_number’) as TButton;
if Assigned(itemNumber) then begin
itemNumber.Text := jsonNumber;
case jsonColor of
0 : itemNumber.TintObject.TintColor := TAlphaColors.Chocolate;
1 : itemNumber.TintObject.TintColor := TAlphaColors.Gold;
2 : itemNumber.TintObject.TintColor := TAlphaColors.Darkgreen;
3 : itemNumber.TintObject.TintColor := TAlphaColors.Deeppink;
end;
end;
//Type
itemType := item.FindStyleResource(‘txtstyle_type’) as TText;
if Assigned(itemType) then begin
itemType.Text := jsonTypeName;
end;
//Occupation
itemOccup := item.FindStyleResource(‘txt_occupation’) as TText;
if Assigned(itemOccup) then begin
itemOccup.Text := jsonOccup;
end;
//Dates
itemDay := item.FindStyleResource(‘txt_day’) as TText;
if Assigned(itemDay) then itemDay.Text := displayDay;
itemDateStart := item.FindStyleResource(‘txt_start’) as TText;
if Assigned(itemDateStart) then itemDateStart.Text := jsonTimeStart;
itemDateEnd := item.FindStyleResource(‘txt_end’) as TText;
if Assigned(itemDateEnd) then itemDateEnd.Text := jsonTimeEnd;
//Item background
itemBackgr := item.FindStyleResource(‘background_item’) as TRectangle;
if Assigned(itemBackgr) then begin
itemBackgr.Fill.Kind := TBrushKind.Solid;
case jsonStatus of
0 : itemBackgr.Fill.Color := TAlphaColors.White;
1 : itemBackgr.Fill.Color := TAlphaColors.Lightgreen;
2 : itemBackgr.Fill.Color := TAlphaColors.Palegoldenrod;
3 : itemBackgr.Fill.Color := TAlphaColors.Lightcoral;
4 : itemBackgr.Fill.Color := TAlphaColors.Lightseagreen;
5 : itemBackgr.Fill.Color := TAlphaColors.Lightblue;
6 : itemBackgr.Fill.Color := TAlphaColors.Lightgrey;
end;
end;

Inc(i);
end;

Thanks so much for your attention.

EDIT 2. SOLUTION

ListBox items change after doing scroll in Firemonkey

Comments are closed.