[英]How to add items to TListView with DynamicAppearance?
How can I add items to DynamicAppearance Listview in runtime?如何在运行时向 DynamicAppearance Listview 添加项目? On design mode I created the layout of ListView which I want.在设计模式下,我创建了我想要的 ListView 布局。 I added 3 TTextObjectAppearance.我添加了 3 个 TTextObjectAppearance。 How can I set those 3 TTextObjectAppearance text dynamically?如何动态设置这 3 个 TTextObjectAppearance 文本?
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.出于某种原因,答案对我来说无法更改 TTextObjectAppearance 项目的文本颜色。 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.