Description: Displays a ListView that automatically adjusts the height of the Detail string length for each row of Item (each row can be of different heights).
Applicable: Delphi XE7
SOURCE download: [Original]listview_ automatic calculation line height (by Tortoise Mountain a swastika). zip
procedureTform1.button1click (sender:tobject);ConstDETAILSTR:Array[0..2] ofString =('1234567890123456789012345678901234567890123456789012345678901234567890','abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz','abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz');varI, R:integer; Item1:tlistviewitem;begin fori:=0 to - Do beginItem1:=ListView1.Items.Add; R:= Random (3); Item1.detail:= Detailstr[r]. Substring (0, Random (Detailstr[r]. Length)); Item1.text:=i.tostring; End;End;procedureTform1.listview1updateobjects (ConstSender:tobject; Constaitem:tlistviewitem);varR:TRECTF;begin if(AItem.Objects.DetailObject <>Nil) and(AItem.Objects.DetailObject.Text<>"') Then begin //calculate the area of text displayR: = RECTF (0,0, AItem.Objects.DetailObject.Width,10000); ListView1.Canvas.MeasureText (R, AItem.Objects.DetailObject.Text, AItem.Objects.DetailObject.WordWrap , [], ttextalign.leading, ttextalign.leading); //Set HeightAitem.height: =Trunc (r.height); End;End;
XE7 ListView automatically calculates row heights