I would like to add a decent AutoResize
mechanism to my Listview but I don't know what to do.
I set the last column to Autoresize itselfs when the Form resizes:
Private Sub Form1_Resize(sender As Object, e As EventArgs) _
Handles MyBase.Resize
ColumnDownload.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize)
End Sub
But this native autoresize method is so wrong because when I resize the application, the horizontal scrollbar is shown:
Ofcourse If I pick by myself with the mouse the last column separator to increase the column width then I want to see/use the horizontal scrollbar, but the framework autoresize just autoincreases the size displaying that horizontal scrollbar, is so ugly an uneficient there's no need to auto display that scrollbar when resizing the form!
The look that I would is just like JDownloader and all the nice programs has, an Autoresize that stops exactly on the start of the vertical scrollbar without showing the ugly horizontal scrollbar if not needed, for example like this:
I hope that you could understand my question.
EDIT:
'Magic solutions' such as these:
MyColumnHeader.Width = -2
MyColumnHeader.Width = -1
...Does the same. See good article here: http://visualbasic.about.com/od/quicktips/qt/ListViewQT.htm
Really all the Google search results about resizing a Listview in .NET are using that, any proportional resize or alternative, any decent auto resizer, incredible.
ObjectListView, a open source wrapper around a .NET ListView, has a FillsFreeSpace
property which does exactly this.
As the user resizes the control, the column will become larger or smaller, such that the horizontal scroll bar is never shown. It was relatively complicated to implement correctly :)
See this link for more details.
[Edit]
Basic scheme:
Resize
event on the ListView.ClientSize
of the ListView.This will work:
private void ResizeLastColumn(int listViewWidth)
{
int totalColumnWidth = 0;
for (int i =0 ; i < listView1.Columns.Count - 1; i++) {
totalColumnWidth += listView1.Columns[i].Width;
}
colLast.Width = Math.Max(listViewWidth - totalColumnWidth, 10);
}
private void listView1_Resize(object sender, EventArgs e)
{
ResizeLastColumn(this.listView1.ClientSize.Width);
}
The limitation on this is that the horizontal scroll bar will flicker slightly when shrinking the control. To get around that, you need to intercept the WM_WINDOWPOSCHANGING
message, and resize the columns to the size that the control is going to become. This is somewhat complicated -- and exactly what ObjectListView does :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With