<p>I've found some examples using the Win32 api or simulating the ^+ button combination (<kbd>ctrl</kbd>-<kbd>+</kbd>) <a href="http://www.codeproject.com/KB/list/AutoResize.aspx" rel="nofollow noreferrer">using SendKeys</a>, but at least with the SendKeys method the listview grabs the cursor and sets it to an hourglass until I hit the start button on my keyboard.  What is the cleanest way to do this?</p>

[{'answer_id': 57682, 'author': 'rpetrich', 'author_id': 4007, 'author_profile': 'https://Stackoverflow.com/users/4007', 'pm_score': 1, 'selected': False, 'text': '<p>According to <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.columnheader.width(VS.71).aspx" rel="nofollow noreferrer">MSDN</a>, if you set the column width to -1 then it will  autosize to the widest item</p>\n'}, {'answer_id': 58102, 'author': 'Matt Nelson', 'author_id': 788, 'author_profile': 'https://Stackoverflow.com/users/788', 'pm_score': 5, 'selected': True, 'text': '<p>Looks like a call to <code>myListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)</code> will do what you want. I would think, just call it after adding an item.</p>\n\n<p>More info <a href="https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.autoresizecolumns(v=vs.110).aspx" rel="noreferrer">here</a></p>\n'}, {'answer_id': 17152584, 'author': 'RonB', 'author_id': 2494210, 'author_profile': 'https://Stackoverflow.com/users/2494210', 'pm_score': 0, 'selected': False, 'text': '<p>loop through all columns and set width to -1 after adding content.</p>\n'}, {'answer_id': 54192601, 'author': 'Chris Raisin', 'author_id': 5316401, 'author_profile': 'https://Stackoverflow.com/users/5316401', 'pm_score': 0, 'selected': False, 'text': '<p>After adding the following routine to your code then call it from any procedure/function. Do not use it in your "Form_Load" procedure though. Only call it after you have added an item to your ListView (or if you are making multiple additions, call it once at the end of all the additions):</p>\n\n<pre><code>    Private Sub AutoSizeListViewColumns(oListView As ListView)\n        Dim nCol As Integer = 0\n        SuspendLayout()\n        For nCol = 0 To (oListView.Columns.Count - 1)\n            oListView.Columns(nCol).Width = -1  \'forces autosizing on column\n        Next\n        oListView.Refresh()\n        ResumeLayout()\n    End Sub\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/57584', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/327/']