Autosize columns for TListView
-
30-09-2019 - |
Question
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
Solution
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;
OTHER TIPS
Try this:
// Assign vsReport;
ListView1.ViewStyle := vsReport;
{ // Add your items }
// Assign vsList again;
ListView1.ViewStyle := vsList;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow