I created a ListView and add some ItemsText's, arranged them in their respective sizes/positions and when try to populate them, some ItemsText was cut in half (short width), then I decide to change all of them with OnUpdatingObjects
Event using Canvas.TextWidth
on Text and adding more 10p in width to be sure.
My Vars ( AItem
comes in OnUpdatingObjects
Event which is TListViewItem
):
var
Drawable : TListItemText;
Text : String;
i : integer;
begin
for i := 0 to AItem.Objects.Count-1 do begin
if AItem.View.Drawables[i].ClassName = 'TListItemText' then begin
Drawable := TlistItemText(AItem.Objects.Drawables[i]);
Text := Drawable.Text;
Drawable.Width := Round(Canvas.TextWidth(Text)) 10;
end;
end;
end;
The width doesn't change and if I do manually like :
TListItemText(Objects.FindDrawable('MyText')).Width := 200;
Doesn't change too.
Already try a lot of different ways to do it, but none of them worked.
PS : The Listview is in DynamicAppearance.
PS.2 : The Drawable variable shows the new value in Width but no changes on ListView, except by the Text Property none of them are changeable.
CodePudding user response:
try using onUpdateObjects
procedure TFHistory.lvMainUpdateObjects(const Sender: TObject;
const AItem: TListViewItem);
var
AText : TListItemText;
begin
AText := AItem.View.FindDrawable('kd') as TListItemText;
AText.Width := 20;
end;
CodePudding user response:
I was a little curious, so I try this with success
procedure TForm2.ListView1UpdateObjects(const Sender: TObject;
const AItem: TListViewItem);
begin
AItem.Objects.FindDrawable('Text2').Width :=Round(Canvas.TextWidth(AItem.Objects.FindObject('Text2').Data.AsString)) 5;
end;