How to add items to TListView with DynamicAppearance?
Asked Answered
E

3

7

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?

Emmittemmons answered 20/5, 2016 at 21:17 Comment(2)
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
V
8

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; 
Vosges answered 20/5, 2016 at 21:17 Comment(0)
B
3

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;
Bananas answered 8/1, 2020 at 14:47 Comment(0)
A
0

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;
Adequate answered 5/3, 2019 at 16:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.