I had a form designed where only a portion of the Listview is showing.
I wanted to Resize the Form and have the LIstview resize with it, but limit the Form Resizing to the
Maximum number of columns in the Listview.
The following code works well for this situation.
I wanted to Resize the Form and have the LIstview resize with it, but limit the Form Resizing to the
Maximum number of columns in the Listview.
The following code works well for this situation.
Code:
Private Sub Form_Resize()
Dim i As Integer
Dim iWidth As Integer
'---------------------------
'---------------------------
'Listview and Form Resizing
'--------------------------
'Keep Miniumu Form Width = Design Width
If Form1.ScaleWidth < lvTable.Width Then
Exit Sub
End If
'Sum the Column Widths
With lvTable
For i = 1 To .ColumnHeaders.Count
iWidth = iWidth + .ColumnHeaders(i).Width
Next
End With
'Make sure Listview Resizes with Form
lvTable.Width = Form1.ScaleWidth
'Keep Max Form Width = Listview Width
If Form1.ScaleWidth > iWidth Then
Form1.Width = iWidth
End If
End Sub