
How to change column width in ListView control in lvwList mode
I'm using mscomctl.ocx from vb6 sp5. As per the Platform SDK documentation,
under LVM_SETCOLUMNWIDTH
lResult = SendMessage( // returns LRESULT in lResult
(HWND) hWndControl, // handle to destination
control
(UINT) LVM_SETCOLUMNWIDTH, // message ID
(WPARAM) wParam, // = (WPARAM) (int) iCol
(LPARAM) lParam // = (LPARAM) MAKELPARAM ((int)
cx, 0)
);
iCol
Zero-based index of a valid column. For list-view mode, this parameter must
be set to zero.
Return Value
Returns TRUE if successful, or FALSE otherwise.
This references the commctrl.h header file which I used to get the constants
to import into my project.
Code fragment:
Private Function SetColumnWidth(lNewTwipWidth) As Long
Const LVM_FIRST = &H1000
Const LVM_GETCOLUMNWIDTH = LVM_FIRST + 29
Const LVM_SETCOLUMNWIDTH = LVM_FIRST + 30
Dim lNewPixelWidth
lNewPixelWidth = lNewTwipWidth / (Screen.TwipsPerPixelX)
SetColumnWidth = SendMessage(ListView1.hwnd, LVM_SETCOLUMNWIDTH, 0,
lNewPixelWidth)
End Function
This does in fact return 1 indicating success. Unfortunately when I call
this it blanks out the ListView control so that nothing is displayed in it.
All the data is there - I can retrieve, set, add ListItem entries etc, but
nothing displays :-( I tried doing a .Refresh thinking I just needed a
Paint, but that didn't help. Any ideas?
Thanks!