I have a WinForm I'm creating using Visual Studio 2013 Express for Windows Desktop in C#.
On the Main form I have a ListView Control with 3 Columns that I added through the VS Properties Window, I want the user to be able to resize the form at their leisure, this works fine so long as they don't exceed the width of all 3 columns added together, once that happens an empty fourth column with no header text shows up and just continues to grow as long as you keep resizing. I end up having 4 columns of which I did not create the last one, as im sure you've figured by now the listview is anchored so that it will expand when the form is resized. I want the listview to expand but I don't want a fourth column, is there a way to allow one of the columns to resize itself / autofill when the form is resized?
You can do that in ListView_Resize
event.
int ColumnIndex = 3; //assign the column index which you want to set autosize
int iWidth = 0;
for ( int i = 0 ; i < ListView1.Columns.Count ; i++ )
{
if (ColumnIndex == i)
continue;
iWidth += ListView1.Columns[i].Width; //Calculating all column width
}
ListView1.Columns[ColumnIndex].Width = ListView1.Width - iWidth;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.