Aug 19, 2011
I got a very simple question regarding resizing listview columns. I have a form with a listview anchored to it (top, bottom, left, right). The form is resizable and the user will be able to resize the listview columns manually. However, I need the listview to resize its columns automatically when the form is resized (especially when its maximized).
View 2 Replies
But, I don't want all the columns to resize, only the ones I choose. For example, the listview will have 6 columns in total (0-5). When the user resizes or maximizes the window, I need only columns 2 and 4 (or columns 3 and 5 or columns 1 and 5) to resize. Now, I have come up with two pieces of code as listed below.
Code Part A: The following code only resizes one column. When the form is maximized, only the column ID provided will resize and fill the rest of the control. It works perfectly but I need to be able to resize multiple columns (as explained above):
Public Sub lvResizeSingleCol(ByVal resizeColumn As Integer, ByVal listViewName As ListView)
Dim w As Integer = 0
For column As Integer = 0 To listViewName.Columns.Count - 1
If column <> resizeColumn Then
w += listViewName.Columns(column).Width