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 my ViewStyle to vsReport.

Thanks in advance

Answers


I got the answer. Setting the column width to -1 or -2 solved the problem.

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

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

ListView1.Columns[0].Width := -1 or -2;

Need Your Help

Cocoa Array of Objects to String

iphone cocoa nsstring nsmutablearray separator

I have an NSMutableArray of objects. Each object has a property called "Name". I want to join them together in a string with a separator " > ".

Is there a way to read HD data past EOF?

c windows hard-drive data-recovery

Is there a way to read a file's data but continue reading the data on the hard drive past the end of file? For normal file I/O I could just use fread(), but, obviously, that will only read to the e...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.