Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: TListView styling issue


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


Permlink Replies: 2 - Last Post: Jun 15, 2016 9:40 AM Last Post By: Markus Humm
Markus Humm

Posts: 5,113
Registered: 11/9/03
TListView styling issue  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 15, 2016 6:13 AM
Hello,

I'm using Delphi 10.1 Berlin to develop an Android app.
As of recommendation from here (to solve performance issues) I use a TListView.
I can add items by code and I managed to set the background color by:

1. adding a TStyleBook on the form, loading one of the supplied styles into it
2. double clicking on that one to open the style editor
3. unfolding listviewstyle and changing the Color of the background item

This works.
Now I tried to do the same in code, but it failed.
I created an OnApplyStyleLookup event for the ListView:

procedure TForm1.ListView1ApplyStyleLookup(Sender: TObject);
var
  Obj: TFMXObject;
begin
  if (Sender is TListView) then
  begin
    Obj := TListView(Sender).FindStyleResource('itembackground');
    if assigned(Obj) then
      if Obj is TColorObject then
        TColorObject(Obj).Color := claSlategray;
  end;
end;


1. It never got called (says the debugger)
2. I added a ListView1.NeedStyleLookup; call to the OnStartShowing event
of the TMultiview the ListView is on. Then it got called and I can step through it and verify,
that the line assigning the color is actually being called.
But: at runtime the listview still has a white background!
StyleLookup of that Listview is the default one 'listviewstyle'.

So why is the OnStyleLookup never called without my manual triggering?
And why doesn't it change the backgroudn color when I manually trigger it?

Greetings

Markus
Stéphane WIERZB...

Posts: 58
Registered: 9/3/00
Re: TListView styling issue  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 15, 2016 9:03 AM   in response to: Markus Humm in response to: Markus Humm
markus.humm wrote:

It's a bug (for me).
I'm also trying to change background color in vain....

My dirty workaround was :
Set listview itemappearance to DynamicAppearance
Add add a TImageObjectAppearance (named couleur) and put it on the left side (It is drawn over the text items....)

My listview is "livebinded"

Filled the Livebinding OnFillingListIem with something like this

var
  LObject: TListItemImage;
  VC: TColor;
begin
  LObject := AItem.Objects.FindObjectT<TListItemImage>('Couleur');
  VC := dtmMain.qrTaches.fieldbyname('couleur').AsInteger;
  if assigned(LObject) and (LObject.Bitmap = nil) then
  begin
 
    LObject.Bitmap := FMX.Graphics.TBitmap.Create(10, 240);
    LObject.Bitmap.Clear(VC);
  end
  else if assigned(LObject) and assigned(LObject.Bitmap) then
    LObject.Bitmap.Clear(VC);
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: TListView styling issue [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 15, 2016 9:40 AM   in response to: Stéphane WIERZB... in response to: Stéphane WIERZB...
Am 15.06.2016 um 18:05 schrieb Stephane Wierzbicki:
markus.humm wrote:

It's a bug (for me).
I'm also trying to change background color in vain....

My dirty workaround was :
Set listview itemappearance to DynamicAppearance
Add add a TImageObjectAppearance (named couleur) and put it on the left side (It is drawn over the text items....)

My listview is "livebinded"

Filled the Livebinding OnFillingListIem with something like this

var
  LObject: TListItemImage;
  VC: TColor;
begin
  LObject := AItem.Objects.FindObjectT<TListItemImage>('Couleur');
  VC := dtmMain.qrTaches.fieldbyname('couleur').AsInteger;
  if assigned(LObject) and (LObject.Bitmap = nil) then
  begin
 
    LObject.Bitmap := FMX.Graphics.TBitmap.Create(10, 240);
    LObject.Bitmap.Clear(VC);
  end
  else if assigned(LObject) and assigned(LObject.Bitmap) then
    LObject.Bitmap.Clear(VC);


Hello,

hm, not exactly what I was hoping for...

I now took the route I had already researched using a TStyleBook.

I fiddled together the already existing style definitions I need for a
special variant of a standard control and the listviewstyle.

But now I have an issue I still need to ressearch and report about the
TStyleBook always loosing its contents when I leave the style designer.
It asks me whether it shall apply my changes, but no matter whether I
click yes, no or cancel these are lost. When I double click again on it
I see it all empty :-(
Maybe he doesn't like it that this one lives on a TDataModule?
Or there is something about the way I combined the two styles via notepad.

But I really do not like to have the default style in a stylebook in my
app, as that would be something to recheck on every update I guess.

Greetings

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

Server Response from: ETNAJIVE02