Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1463

Resizing ListView to Form and Vice Versa

$
0
0
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.



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


Viewing all articles
Browse latest Browse all 1463

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>