How to increase row height of listview in report style?
Asked Answered
T

2

10

I need to add just 2px :) to a height of a row in a list view (a custom drawn progress bar is too narrow now).

There are two good answers Change Listview item height, http://www.delphipages.com/forum/showthread.php?t=49939, but I couldn't do it.

I know that it is possible to do with an image list, but I have already 16x16 images :)

Can anybody help me? I'll appreciate it.

Threefold answered 15/8, 2011 at 0:10 Comment(0)
S
16

Respond to the CN_MEASUREITEM control notification message, as follows:

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

  TForm1 = class(TForm)
    ...

procedure TListView.CNMeasureItem(var Message: TWMMeasureItem);
begin
  inherited;
  Inc(Message.MeasureItemStruct.itemHeight, 2);
end;

Note: this message will only be send if the OwnerDraw property is true.

Shilohshim answered 15/8, 2011 at 0:32 Comment(9)
Wow! Thanks!!! I saw a source code of TMS' TAdvListView and this message CNDrawItem(var Message: TWMDrawItem); is handled too (the link delphipages has the same code as in TMS). Why?Threefold
Dunno TAdvListView. The default TListView has the OnDrawItem event already.Shilohshim
id doesn't matter much :) It works!!! You are a good programmer & as a person! Thanks!Threefold
One "small" and funny bug :) -> ListView1.Align:=alClient; please add items, resize a window and see what will happen :) How to fix? Thanks!Threefold
Yeah, you probably are better off with Message.MeasureItemStruct.itemHeight := 21;.Shilohshim
This doesn't work with a TCustomListView - can't seem to find the way of doing this.Brigitta
@Brigitta Strange. Maybe the why is worth its own question.Shilohshim
great solution! is there any way to change the header row's height?Tryptophan
@Tryptophan Not easy. The fun starts by retrieving the header control with the ListView_GetHeader macro, but simply setting its height won't do. You have to respond to all the messages resetting the height as well as adjusting the list view's client rect. If you are really interested, then you should ask a new question linking to this one, because a complete answer would not fit here.Shilohshim
E
9

A quick and dirty alternative without writing any code would be to add a TImageList, set its width to 1 and its height to whatever you want the lines height to be and assign it to the SmallImages of the listview.

Eccles answered 30/4, 2016 at 17:51 Comment(2)
I don't think it's a "dirty" alternative, works perfectly without side effects!Ula
I am using actually SmallImages property, thus it is not a good solution for me. But, as found at https://mcmap.net/q/479013/-c-change-listview-item-39-s-row-39-s-height, you can use also StateImages for this purpose!Travistravus

© 2022 - 2024 — McMap. All rights reserved.