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?

Kromster
  • 7,181
  • 7
  • 63
  • 111
shariful
  • 455
  • 1
  • 9
  • 21
  • Got it working: var list : TListViewItem; ldes, lOrder, lLegal : TListItemText; begin list := ListView1.Items.Add; ldes := list.Objects.FindObjectT('Description'); lOrder := list.Objects.FindObjectT('OrderId'); lLegal := list.Objects.FindObjectT('LegalCode'); ldes.Text := 'Mouri'; lOrder.Text := 'Love'; lLegal.Text := 'You' end; – shariful May 20 '16 at 21:28
  • 3
    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. – Rob Kennedy May 20 '16 at 21:41

3 Answers3

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; 
Adriaan
  • 806
  • 7
  • 24
Freddie Bell
  • 2,186
  • 24
  • 43
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;
Aimery
  • 1,559
  • 1
  • 19
  • 24
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;
cdsaenz
  • 520
  • 1
  • 10
  • 15