How can I set the column width of a c# winforms listview control to auto. Something like width = -1 / -2 ?
It is also worth noting that ListView may not display as expected without first changing the property:
myListView.View = View.Details; // or View.List
For me Visual Studio seems to default it to View.LargeIcon for some reason so nothing appears until it is changed.
Complete code to show a single column in a ListView and allow space for a vertical scroll bar.
lisSerials.Items.Clear();
lisSerials.View = View.Details;
lisSerials.FullRowSelect = true;
// add column if not already present
if(lisSerials.Columns.Count==0)
{
int vw = SystemInformation.VerticalScrollBarWidth;
lisSerials.Columns.Add("Serial Numbers", lisSerials.Width-vw-5);
}
foreach (string s in stringArray)
{
ListViewItem lvi = new ListViewItem(new string[] { s });
lisSerials.Items.Add(lvi);
}