Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to change background color of a TListView item in Delphi 10?



Permlink Replies: 1 - Last Post: Mar 20, 2018 1:49 PM Last Post By: Markus Humm
WILLIAM BENATTI

Posts: 5
Registered: 11/20/17
How to change background color of a TListView item in Delphi 10?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 16, 2018 9:47 AM
Using Firemonkey I created a list with TListView. I want to change the background color of the item when I click on the list AND the color has to be retained even if I click on another item in the list.

Example: If the user clicks Item AAA it'll change its color to green. After that, if the user clicks on another item in the list, Item BBB for example, this item will also turn green, as well as the Item AAA that remains green the same way.

At runtime I've tried this code, which gives no error, but also does not change the color. Also I want to change only the color of the selected item.

procedure TForm1.lvListasItemClickEx(const Sender: TObject; ItemIndex: Integer;
  const LocalClickPos: TPointF; const ItemObject: TListItemDrawable);
var Obj: TFmxObject;
begin
   Obj := ListView1.FindStyleResource('itembackground');
   if Obj <> nil then
   begin
      TColorObject(Obj).Color := TAlphaColorRec.Blue;
   end;
end;


How do I change the background color of selected item?
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: How to change background color of a TListView item in Delphi 10?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 20, 2018 1:49 PM   in response to: WILLIAM BENATTI in response to: WILLIAM BENATTI
Am 16.03.2018 um 17:47 schrieb WILLIAM BENATTI:
Using Firemonkey I created a list with TListView. I want to change the background color of the item when I click on the list AND the color has to be retained even if I click on another item in the list.

Example: If the user clicks Item AAA it'll change its color to green. After that, if the user clicks on another item in the list, Item BBB for example, this item will also turn green, as well as the Item AAA that remains green the same way.

At runtime I've tried this code, which gives no error, but also does not change the color. Also I want to change only the color of the selected item.

procedure TForm1.lvListasItemClickEx(const Sender: TObject; ItemIndex: Integer;
  const LocalClickPos: TPointF; const ItemObject: TListItemDrawable);
var Obj: TFmxObject;
begin
   Obj := ListView1.FindStyleResource('itembackground');
   if Obj <> nil then
   begin
      TColorObject(Obj).Color := TAlphaColorRec.Blue;
   end;
end;


How do I change the background color of selected item?

Hello,

afaik in form designer you can create a new style by right clicking on a
ListViewItem and select the proper menu of the context menu. Then
customize that style and when somebody clicks your list view item assign
that stile instead of the default one.

Greetings

Markus
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02