I have a Win Form with two columns and I wanted to have the 1st column width 2/3 of the size of the ListView size and the second column 1/3. I wanted to be able to fill the ListView with the 2 columns and be able to shrink and expand it to allow room for a vertical scroll bar if the ListView items goes below the bottom of the box. I have come up with this code but this only will take effect when the scroll bar is there, and even then it expands the columns slightly so a horizonal scrollbar is created which I don’t want. Any help is very appreciated.
private void AddColumn()
{
listView1.View = View.Details;
listView1.Columns.Add("Item");
listView1.Columns.Add("Date Added");
int itemColumnWidth = listView1.Width - SystemInformation.VerticalScrollBarWidth;
listView1.Columns[0].Width = itemColumnWidth / 3 * 2;
listView1.Columns[1].Width = itemColumnWidth / 3;
}
What you can do is resize the first column to be 2/3 width and set the second column to expand to the remaining width.
The method for expanding the second column to remaining width is explained in the answer to this question: ListView Final Column Autosize creates scrollbar