开发者

Change Listview item height

I need to make more room between each list item. Is it possible to change Listview item 开发者_运维知识库height in Delphi?


What mode is your TListView in? (There are 4, and things change for different modes - that's why there are different modes in the first place.)

Since you're asking about height, I'm guessing you're in vsList mode. In this case, the height of each row is determined by the height of the SmallImages Imagelist. You can change the row height by assigning taller images to that ImageList.


The Delphi TListView control is a wrapper around the Microsoft control. It descends from TCustomMultiSelectListControl. While the TListView does not expose an ItemHeight property, the TCustomMultiSelectListControl is also the ancestor for the TListBox, which does expose this property.

The TListBox's ItemHeight property is implemented in TCustomListBox (which descends from TCustomMultiSelectListControl). Although the property is not in the common ancestor, wading through MSDN seems to indicate that the standard listview and listbox controls share many messages, amongst which the LB_SETITEMHEIGHT. Unfortunately, that message is nowhere to be found in the VCL.

From what I can gather from a cursory glance at the implementation of SetItemHeight in TCustomListBox and the use of (F)ItemHeight in that class, you would need to:

  • create a TListView descendant
  • add your own ItemHeight property with getter and setter
  • implement the getter and setter along the lines of TCustomListBox which involves causing the control's handle to be recreated in the setter
  • override/reimplement the handler for CN_MEASUREITEM to use (F)ItemHeight as appropriate
  • override/reimplement the paint method to use (F)ItemHeight as appropriate
  • anything I have overlooked in my cursory glance

All in all not a simple exercise. If you your app permits it and you can switch to a TListBox or a TColumnListBox, your task will become a lot easier...

Update

Seeing Ken's answer. Of course using the ImageList to change the ItemHeight is vsList mode is a much easier approach!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜