Recent

Author Topic: Column size in TListview (vsReport with TImagelist linked) apparently random.  (Read 541 times)

elioenaishalom

  • New Member
  • *
  • Posts: 22
My ListView was OK, but when I added pictures to column 2, the caption column, with or without checkbox, showed erratic behavior.
(see picture added)
Is that the way it should be?
Any alignment gives the same result.

Can anyone clarify? Thank you in advance.  :D

Lazarus 2.0.2 32bit Ideapad 15IKB Notebook, I7-7500U Processor, 16.0 GB RAM - Windows 10 Home 1809 OS

jamie

  • Hero Member
  • *****
  • Posts: 2166
I see the image but I don't see what the erratic behavior is?

Are you referring to the selection in blue? if so that is normal for selecting the Row I guess.

if this is something else I am not seeing please advise...

btw.

 TImageList by default assumes all images are of the same size so if you are using this as an ICON
view then I would assume each image you added was resized to fix the size?

 Also there is a recent release of Lazarus, 2.0.4. I can't say that it will fix your issue but I Know it will solve some leaks that existed in 2.0.2


 I wanted to add that you can I believe do OwnerDraw mode, this means you can custom draw the surfaces.

« Last Edit: August 12, 2019, 12:46:37 am by jamie »
Number 1 at blue screen app creations!

elioenaishalom

  • New Member
  • *
  • Posts: 22
Mr. Jamie,

Thank you for your interest.

Line Selection: The line is only partially selected, reserving an area to the right of the checkbox.

Style: ViewStyle is vsReport;
All figures are pre-existing with the same size (128x72 pixels) and are added to TImagelist at run-time during the first Form.activate.

I have attached version without TImageList and with TImageList. Please verify.

Column resize: It seems to me that when using pictures, an area is allocated to the right of the checkbox equivalent to the width of the picture even without using a picture in the caption column.

OwnerDraw: I'm sorry but I have no experience and don't master OwnerDraw mode; perhaps I will soon dive into this ocean.

wp

  • Hero Member
  • *****
  • Posts: 6485
Please provide a compilable example project showing the issue.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

elioenaishalom

  • New Member
  • *
  • Posts: 22
Mr. wp,

attached a project for your verification.
I provided four same-sized bitmaps (128x72 pixels) to populate Listview.
I hope it fits your demand.

Thank you.
« Last Edit: August 12, 2019, 05:36:59 pm by elioenaishalom »

elioenaishalom

  • New Member
  • *
  • Posts: 22
 :o
OK, so be it ...
the caption column allocates the width of the picture plus 5 pixels, cf. the attached tests with 3 different picture widths.
Excuse me but any  ;) like myself concludes the component is not correct as the user is captive of this abnormal behavior.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7625
Locking threads is only for special cases, not a matter of routine.

It is considered not proper behaviour not allowing other people the ability to comment.

wp

  • Hero Member
  • *****
  • Posts: 6485
I don't know if this is a bug or a feature. When an ImageList is attached to a ListView, the captions in the first column move to the right to give way to the images. Drawing images only when needed would result in a ragged left side of the 1st column which looks strange. It should also be noted that the Listview is painted essentially by the widgetset, i.e. by routines of the operating system. Therefore, the LCL cannot change this behavior.

You could try to remove the ImageList from Listview and owner-draw the column with the images in the OnCustomDrawSubItem event:

Code: Pascal  [Select]
  1. procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
  2.   Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  3.   var DefaultDraw: Boolean);
  4. var
  5.   R: TRect;
  6. begin
  7.   R := Item.DisplayRectSubItem(1, drBounds);  // 1 = index of image column
  8.   ImageList1.Draw(Sender.Canvas, R.Left, R.Top, Index);
  9. end;
When doing this I faced the problem that I did not find a way how to increase the row heights of the ListView to fit the image heights. Maybe it is easy, maybe it requires system calls - I don't know...

But normally I would not use a TListView for this programming task at all. I'd use a plain old StringGrid instead which can be configured to look almost like a TListView and allows much more control. I am attaching a modified version of your demo based on a stringGrid.
« Last Edit: August 13, 2019, 04:20:52 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

elioenaishalom

  • New Member
  • *
  • Posts: 22
OK thank you for the attention