You gave the answer: -2 will autosize the column to the length of the text in the column header, -1 will autosize to the longest item in the column. All according to MSDN. Note though that in the case of -1, you will need to set the column width after adding the item(s). So if you add a new item, you will also need to assign the width property of the column (or columns) that you want to autosize according to data in ListView control.
I made a program that cleared and refilled my listview multiple times. For some reason whenever I added columns with width = -2 I encountered a problem with the first column being way too long. What I did to fix this was create this method.
Expanding a bit on Fredrik's answer, if you want to set the column's auto-resize width on the fly
for example: setting the first column's auto-size width to 70:
This solution will first resize the columns based on column data, if the resized width is smaller than header size, it will resize columns to at least fit the header. This is a pretty ugly solution, but it works.
I believe the author was looking for an equivalent method via the IDE that would generate the code behind and make sure all parameters were in place, etc. Found this from MS:
You can use something like this, passing the ListView you want in param
private void AutoSizeColumnList(ListView listView)
{
//Prevents flickering
listView.BeginUpdate();
Dictionary<int, int> columnSize = new Dictionary<int,int>();
//Auto size using header
listView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
//Grab column size based on header
foreach(ColumnHeader colHeader in listView.Columns )
columnSize.Add(colHeader.Index, colHeader.Width);
//Auto size using data
listView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
//Grab comumn size based on data and set max width
foreach (ColumnHeader colHeader in listView.Columns)
{
int nColWidth;
if (columnSize.TryGetValue(colHeader.Index, out nColWidth))
colHeader.Width = Math.Max(nColWidth, colHeader.Width);
else
//Default to 50
colHeader.Width = Math.Max(50, colHeader.Width);
}
listView.EndUpdate();
}