2

I have this list view in csharp and would like the columns to fill the entire space but I cannot find that property. In the DataGridView there is a property called AutoSizeColumnMode is there such a property in the listView

enter image description here

Swarup
  • 95
  • 1
  • 3
  • 15
Elias
  • 47
  • 7

2 Answers2

4

You can do this,

YourListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
YourListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

EDIT

Since you wanted the columns to be equally sized, as @berkay mentioned, you could do this,

foreach (ColumnHeader column in YourListView.Columns){
     column.Width = YourListView.Width / YourListView.Columns.Count;
}

The above code will read each column height and and divide the total width by the number of columns.

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • Many thanks Sajeetharan. But it does not fill the entire space. two columns to be split equally among the listView – Elias Apr 10 '17 at 12:28
  • you might have to write some code for that, check this https://nickstips.wordpress.com/2010/11/10/c-listview-dynamically-sizing-columns-to-fill-whole-control/ – Sajeetharan Apr 10 '17 at 12:32
3

Try this,

foreach (ColumnHeader column in listView1.Columns){
     column.Width = listView1.Width / listView1.Columns.Count;
}

Hope helps,

Berkay Yaylacı
  • 4,383
  • 2
  • 20
  • 37