Hi TMS,
another quick question : Is it possible to color items in the TableView list for ex. to indicate the state of something, the red items are overdue, the yellow will become overdue and green is ok still ?
Thanks in adv.
Helge
Hi,
Yes you can with the following code:
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
it: TTMSFMXTableViewItem;
begin
TMSFMXTableView1.BeginUpdate;
TMSFMXTableView1.Items.Clear;
for I := 0 to 9 do
begin
it := TMSFMXTableView1.Items.Add;
it.DataString := IntToStr(Random(3));
it.Caption := 'Item ' + IntToStr(I);
end;
TMSFMXTableView1.EndUpdate;
end;
procedure TForm1.TMSFMXTableView1ItemCustomize(Sender: TObject;
AItem: TTMSFMXTableViewItem; AItemShape: TTMSFMXTableViewItemShape;
AItemControlShape: TControl);
begin
if AItem.DataString <> '' then
begin
case StrToInt(AItem.DataString) of
0: AItemShape.Fill.Color := claYellow;
1:
begin
AItemShape.Fill.Color := claGreen;
AItemShape.ShapeCaption.TextSettings.FontColor := claWhite;
end;
2:
begin
AItemShape.Fill.Color := claRed;
AItemShape.ShapeCaption.TextSettings.FontColor := claWhite;
end;
end;
end;
end;
Pieter Scheldeman2016-06-24 08:34:19
Oh cool, exactly what I needed.
Thank you very much, good Sir! :)
Helge
It does not work.
As far as I can see the DoCustomize is called when I add the item (it := TMSFMXTableView1.Items.Add), but at this point I wasn't able to set additional data for the status. Afterwards the event isn't called anymore.
Helge
The event is called with every update, in which case do you want to color the items? A BeginUpdate en EndUpdate should retrigger the event.
I found the error : I used the BeginUpdate/EndUpdate of the items and not the TableView. Stupid CodeCompletion, told me that there is no BeginUpdate for the TableView, that's why I just assumed it must be the items, which also makes sense.
Now seeing it, it's really agressive to colo the whole Item, is it possible to just color the Left side under the Icon. I tried
AItemShape.ShapeLeftRectangle.Fill.Color := claYellow;
but saw no difference :S
Thanks again
Helge
This should be possible yes but you should also try to set the Fill kind to solid and make sure you have included the leftrectangle in the itemoptions
That worked, thanks again... And sorry to have bothered you on Sunday. Enjoy the rest of your weekend :)
Helge
No problem, thanks !!!