Change Listview item height

后端 未结 2 451
谎友^
谎友^ 2021-01-13 07:56

I need to make more room between each list item. Is it possible to change Listview item height in Delphi?

相关标签:
2条回答
  • 2021-01-13 08:17

    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 讨论(0)
  • 2021-01-13 08:22

    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.

    0 讨论(0)
提交回复
热议问题