How can I add items to DynamicAppearance Listview in runtime? On design mode I created the layout of ListView which I want. I added 3 TTextObjectAppearance. How can I set those 3 TTextObjectAppearance text dynamically?
How to add items to TListView with DynamicAppearance?
Asked Answered
Got it working: var list : TListViewItem; ldes, lOrder, lLegal : TListItemText; begin list := ListView1.Items.Add; ldes := list.Objects.FindObjectT<TListItemText>('Description'); lOrder := list.Objects.FindObjectT<TListItemText>('OrderId'); lLegal := list.Objects.FindObjectT<TListItemText>('LegalCode'); ldes.Text := 'Mouri'; lOrder.Text := 'Love'; lLegal.Text := 'You' end; –
Emmittemmons
Welcome to Stack Overflow. Congratulations on solving your problem. Please add your solution in the answer section below so that it's clear to future visitors that this problem is solved. Comments here should be regarded as ephemeral. –
Sunburst
I took the time to format the answer that was posted in the original question's comments by the original poster.
var list : TListViewItem;
ldes, lOrder, lLegal : TListItemText;
begin
list := ListView1.Items.Add;
ldes := list.Objects.FindObjectT<TListItemText>('Description');
lOrder := list.Objects.FindObjectT<TListItemText>('OrderId');
lLegal := list.Objects.FindObjectT<TListItemText>('LegalCode');
ldes.Text := 'Mouri';
lOrder.Text := 'Love';
lLegal.Text := 'You'
end;
Another way to change the text would be:
for i := 0 to Listview1.Itemcount-1 do begin
Listview1.Items.AppearanceItem[i].Data['Description'] := 'Mouri';
Listview1.Items.AppearanceItem[i].Data['OrderID'] := 'loves';
Listview1.Items.AppearanceItem[i].Data['LegalCode'] := 'YOU!';
end;
For some reason, the answer wasn't working for me to change the text color of a TTextObjectAppearance item. What I did, on a bound/design-made (dynamicAppeareance) Listview is the following:
procedure TReportsForm.lvwReportsUpdateObjects(const Sender: TObject;
const AItem: TListViewItem);
var drw: TListItemDrawable;
cpt: string;
begin
drw:=AItem.Objects.FindDrawable('Concept');
if (drw <> nil) then begin
cpt := AItem.Data['Concept'].AsString;
if (cpt = 'BAD') then
(drw as TListItemText).TextColor := TAlphaColorRec.Indianred
else
(drw as TListItemText).TextColor := TAlphaColorRec.Cadetblue
end;
end;
© 2022 - 2024 — McMap. All rights reserved.