Automatically Resize listview columns

  • Thread starter Thread starter Andibevan
  • Start date Start date
A

Andibevan

Is there a way to automatically resize listview columns?

I can find guidance on how to do this in VB6 but these don't transfer into
Access?

Any ideas / examples?

TIA

Andi
 
Andibevan said:
Is there a way to automatically resize listview columns?

I can find guidance on how to do this in VB6 but these don't transfer into
Access?

Any ideas / examples?

TIA

Andi

Sorry - I posted too quickly and found the solution :-

Add the following to a BAS module in your project:


Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long


Public Const LVSCW_AUTOSIZE = -1&
Public Const LVSCW_AUTOSIZE_USEHEADER = -2& ' not used in this
example, but may apply to other situations.
Public Const LVM_FIRST = &H1000&
Public Const LVM_SETCOLUMNWIDTH = (LVM_FIRST + 30)


And then, use the following code after you have populated your ListView:


Dim lCtr As Long


'Auto-size each column in the listview if it's in Report view.
If ListView1.View = lvwReport Then
For lCtr = 0 To ListView1.ColumnHeaders.Count - 1
Call SendMessage(ListView1.hwnd, LVM_SETCOLUMNWIDTH, lCtr,
LVSCW_AUTOSIZE)
Next
End If


The check to make sure it's in Report view doesn't seem to be necessary as
it appears the ListView will ignore the message if it's in one of the other
view modes, but you never can be too safe.
 
Back
Top