I’m trying to use TLinkControlToField
binding with TListview
, with the event OnFilledListItem
of TLinkControlToField
.
However, as the data is filled in the TListview
, I am able to customise the TListItemText
but not the TListItemTextButton
.
TForm1 = class(TForm)
ListView1: TListView;
PrototypeBindSource1: TPrototypeBindSource;
BindingsList1: TBindingsList;
LinkFillControlToField1: TLinkFillControlToField;
procedure LinkFillControlToField1FilledListItem(Sender: TObject;
const AEditor: IBindListEditorItem);
private
FInteger: Integer;
public
{ Public declarations }
end;
procedure TForm1.LinkFillControlToField1FilledListItem(Sender: TObject;
const AEditor: IBindListEditorItem);
begin
var LItem := AEditor.CurrentObject as TListViewItem;
var LTextObject := LItem.Objects.FindDrawable('Text1') as TListItemText;
if Assigned(LTextObject) then
begin
LTextObject.Text := FInteger.ToString;
LTextObject.Visible := (FInteger mod 2) = 0; // does not hide
if not LTextObject.Visible then
LTextObject.Text := ''; // have to resort to .Text = empty to hide
end;
var LButtonObject := LItem.Objects.FindDrawable('TextButton2') as TListItemTextButton;
if Assigned(LButtonObject) then
begin
LButtonObject.Text := 'test' + FInteger.ToString;
// just make alternate rows invisible for testing purpose
LButtonObject.Visible := (FInteger mod 2) = 0; // does not make it invisible
if not LButtonObject.Visible then
begin
LButtonObject.Height := 0.1; // does not work!
LButtonObject.Width := 0.1; // does not work!
end;
end;
Inc(FInteger);
end;
You can copy and paste these components for convenience:
object ListView1: TListView
ItemAppearanceClassName = 'TDynamicAppearance'
ItemEditAppearanceClassName = 'TDynamicAppearance'
HeaderAppearanceClassName = 'TListHeaderObjects'
FooterAppearanceClassName = 'TCustomizeItemObjects'
Position.X = 744.000000000000000000
Position.Y = 120.000000000000000000
Size.Width = 257.000000000000000000
Size.Height = 401.000000000000000000
Size.PlatformDefault = False
TabOrder = 4
ItemAppearanceObjects.ItemObjects.ObjectsCollection = <
item
AppearanceObjectName = 'Text1'
AppearanceClassName = 'TTextObjectAppearance'
Appearance.TextShadow.Color = claSlategray
Appearance.Width = 79.000000000000000000
Appearance.Height = 44.000000000000000000
end
item
AppearanceObjectName = 'TextButton2'
AppearanceClassName = 'TTextButtonObjectAppearance'
Appearance.TextColor = claSlategray
Appearance.TintColor = claSteelblue
Appearance.Width = 50.000000000000000000
Appearance.Align = Trailing
Appearance.VertAlign = Center
Appearance.Text = 'Edit'
end>
ItemAppearanceObjects.ItemEditObjects.ObjectsCollection = <
item
AppearanceObjectName = 'Text1'
AppearanceClassName = 'TTextObjectAppearance'
end>
end
object PrototypeBindSource1: TPrototypeBindSource
AutoActivate = True
AutoPost = False
RecordCount = 5
FieldDefs = <
item
Name = 'CustomerID'
FieldType = ftInteger
Generator = 'UIntegers'
end
item
Name = 'CustomerType'
FieldType = ftUInteger
Generator = 'UIntegers'
end>
ScopeMappings = <>
Left = 688
Top = 184
end
Am I using OnFilledListItem
wrongly? I need to customize each row. I have partial success with the Text in TListview
but not the TextButton of TListview
.
Is there possibly a bug in the TextButton portion?