开发者

Autosize columns for TListView

I want to auto-size all the columns in the TListView. I am using below code, but its not doing any thing.

ListView1.Columns.Add.Caption := 'Field Name';
ListView1.Columns.Items[0].Autosize := True;

How can i auto-size the columns of TListView in Delphi.

I set 开发者_JAVA百科my ViewStyle to vsReport.

Thanks in advance


I got the answer. Setting the column width to LVSCW_AUTOSIZE or LVSCW_AUTOSIZE_USEHEADER solved the problem.

Use LVSCW_AUTOSIZE setting to set the column header to the size of the largest subitem text in the column,

and a LVSCW_AUTOSIZE_USEHEADER setting to set the column header to the size of the text in the column header.

uses CommCtrl;

ListView1.Columns[0].Width := LVSCW_AUTOSIZE or LVSCW_AUTOSIZE_USEHEADER;


Try this:

// Assign vsReport;    
ListView1.ViewStyle := vsReport; 

  { // Add your items  }

// Assign vsList again;
ListView1.ViewStyle := vsList; 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜