0

In a 32-bit VCL Application in Windows 10 in Delphi 11 Alexandria, I use a TListView where ViewStyle = vsReport.

How can I customize the Row Height of a TListView, BOTH when OwnerDraw is True or False?

I tried this approach:

type
  TListView = class(ComCtrls.TListView)
  private
    procedure CNMeasureItem(var Message: TWMMeasureItem); message CN_MEASUREITEM;
  end;

...

procedure TListView.CNMeasureItem(var Message: TWMMeasureItem);
begin
  inherited;
  Message.MeasureItemStruct.itemHeight := 32;
end;

However, this works only if OwnerDraw = True. Is there no other solution?

user1580348
  • 5,721
  • 4
  • 43
  • 105
  • Do you want different items to have different row heights? – Andreas Rejbrand Feb 13 '22 at 20:24
  • As per [Change Listview item height](https://stackoverflow.com/q/5569779/4299358) and [How to increase row height of listview in report style?](https://stackoverflow.com/q/7060617/4299358) through setting e.g. `.SmallImages` to a `TImageList` with your favorite `.Height`. It does not need to have actual images. – AmigoJack Feb 13 '22 at 20:57
  • *Why* do you want to change the row height? – Andreas Rejbrand Feb 13 '22 at 21:02
  • "Why do you want to change the row height?" - To offer the user a customization option: Hi might feel the rows are too narrow, and an increased row height might give him better readability. – user1580348 Feb 13 '22 at 21:27
  • "Do you want different items to have different row heights?" - No, I want all rows to have the same height. – user1580348 Feb 13 '22 at 21:29
  • @user1580348: (1) If you want accessibility, you generally should *not* change the default behaviour of the Win32 controls. Windows' accessibility tools, as well as third-party accessibility tools, work best (by far) when the controls are not owner-drawn or modified in any strange or non-standard way. (2) If you change the row height manually, it becomes your responsibility to also take DPI scaling into account. (48 px height might seem generous, but not on a very high-resolution screen.) (3) Maybe you just want to increase the list view's font size? That will also increase the item height. – Andreas Rejbrand Feb 13 '22 at 21:31
  • @AndreasRejbrand The default `Message.MeasureItemStruct.itemHeight` with any font size results in a value of **21**. Please try it out. BTW, my ListView IS ownerdrawn. – user1580348 Feb 13 '22 at 21:36
  • If you don't owner draw, increasing the font size increases the item height. If you do owner draw, you can set the height yourself. No? – Andreas Rejbrand Feb 13 '22 at 21:40
  • @AndreasRejbrand I don't know of any accessibility options that allow customizing a ListView's row height. And I don't force the user to have a custom row height. He has the choice in the app's preferences to have a custom row height or not. Default is NO custom row height. – user1580348 Feb 13 '22 at 21:49
  • I see. But in any case, the answer to your question is, "No, if a list-view control is *not* owner-drawn, the only ways to increase the row height is to (1) increase the font size or (2) add an image list of suitable height." – Andreas Rejbrand Feb 13 '22 at 22:23
  • But increasing the row height through font size doesn't solve the user's problem who wants more space between the rows. This is a logical vicious circle. And adding an "image list of suitable height" doesn't help if the ListView already has an ImageList that fits the functionality of the ListView. So the only solution for a ListView's row height customization IMO is to make the ListView completely owner drawn and then use the `CNMeasureItem` functionality. And that's what I have now done. – user1580348 Feb 13 '22 at 23:46
  • 1
    @user1580348: Great! It is very true that if you need fine and precise control, owner-drawing is the right thing to do. – Andreas Rejbrand Feb 14 '22 at 08:40

0 Answers0