title: C# Listview Auto Column resize by both columns and header
body: <p>I need a listview to auto-resize its columns based on both width of the headers and content, and every other answer only does one or the other.</p>
  
  <p>Example:</p>
  
  <pre><code>        listView1.GridLines = true;
          // Create three items and three sets of subitems for each item.
          ListViewItem item1 = new ListViewItem("item1asdfghjkl", 0);
          item1.SubItems.Add("1");
          item1.SubItems.Add("2");
          item1.SubItems.Add("3");
          ListViewItem item2 = new ListViewItem("item2", 1);
          item2.SubItems.Add("4");
          item2.SubItems.Add("5");
          item2.SubItems.Add("6");
          ListViewItem item3 = new ListViewItem("item3", 0);
          item3.SubItems.Add("7");
          item3.SubItems.Add("8");
          item3.SubItems.Add("9");
  
          // Create columns for the items and subitems. 
          // Width of -2 indicates auto-size.
          listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
          listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
          listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left);
          listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Left);
  
          //these two lines
          listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
          listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
  
          //Add the items to the ListView.
          listView1.Items.AddRange(new ListViewItem[] { item1, item2, item3 });
  </code></pre>
  
  <p>the note here is that no matter which (or both) resize style, something is cut off, either a header or a content. </p>
  
  <p>There doesn't even seem to be a reliable way to get the display size of the content to manually resize the columns and headers.</p>