Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: [Delphi 10.1 - Android] Change color of text of a TListViewItem


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Oct 31, 2016 8:02 AM Last Post By: Michele Costant...
Michele Costant...

Posts: 55
Registered: 11/1/11
[Delphi 10.1 - Android] Change color of text of a TListViewItem  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 23, 2016 9:02 AM
Hi!
I've not found any example anywhere...so i'm asking here...
I've a Tlistview in my android project with some custom listviewitems.
Depending on the text value i wanna change the text color of the item.
For example if my ListViewItem called "name" = "John" I wanna "John" in red.

Any idea?

Many thanks!

PS: I think i should use the OnPaint event of the main ListView...but i'm not sure...any example?
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: [Delphi 10.1 - Android] Change color of text of a TListViewItem  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 24, 2016 1:41 PM   in response to: Michele Costant... in response to: Michele Costant...
Am 23.10.2016 um 18:02 schrieb Michele Costantino:
Hi!
I've not found any example anywhere...so i'm asking here...
I've a Tlistview in my android project with some custom listviewitems.
Depending on the text value i wanna change the text color of the item.
For example if my ListViewItem called "name" = "John" I wanna "John" in red.

Any idea?

Many thanks!

PS: I think i should use the OnPaint event of the main ListView...but i'm not sure...any example?

Hello,

you can create a copy of the ListViewItemStyle and apply that to the
ListViewItem. That copy can be changed as desiged via style designer.

Greetings

Markus
Douglas Rudd

Posts: 314
Registered: 5/16/97
Re: [Delphi 10.1 - Android] Change color of text of a TListViewItem  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 24, 2016 4:10 PM   in response to: Michele Costant... in response to: Michele Costant...
You can do it like this in the OnUpdateObjects event of the ListView.
For instance if the text is in the text object:
procedure TForm.ListViewUpdateObjects(const Sender: TObject;
  const AItem: TListViewItem);
begin
 if AItem.Objects.TextObject.Text.Contains('John') then // find the one to change
    AItem.Objects.TextObject.TextColor:= Talphacolorrec.Red;
end;

You can do the same with the DetailObject text.
Michele Costant...

Posts: 55
Registered: 11/1/11
Re: [Delphi 10.1 - Android] Change color of text of a TListViewItem  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 31, 2016 7:58 AM   in response to: Douglas Rudd in response to: Douglas Rudd
Douglas Rudd wrote:
You can do it like this in the OnUpdateObjects event of the ListView.
For instance if the text is in the text object:
procedure TForm.ListViewUpdateObjects(const Sender: TObject;
  const AItem: TListViewItem);
begin
 if AItem.Objects.TextObject.Text.Contains('John') then // find the one to change
    AItem.Objects.TextObject.TextColor:= Talphacolorrec.Red;
end;

You can do the same with the DetailObject text.

procedure TTabbedwithNavigationForm.ListView1UpdateObjects(
const Sender: TObject; const AItem: TListViewItem);
var
dbstr:string;
begin
dbstr:=AItem.Data['Band'].AsString; //just for debugging
if AItem.Data['Band'].AsString='John' then
AItem.Objects.TextObject.TextColor:= Talphacolorrec.Red;
end;

dbstr is always '' during the debug :°( so no color
I forgot to say that i don't use standard listview, but a custom one with some more fields (like the "Band" text field).

Any idea?

Edited by: Michele Costantino on Oct 31, 2016 8:02 AM

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

Server Response from: ETNAJIVE02