February 16th, 2000, 12:08 AM
I have a listview in lvwReport view. My concern is how to display numbers, whole or with cents part, right-aligned. If I right-aligned the column for those values, the column header becomes right-aligned also, which looks ugly. And how do I also make the columns' widths just right to fit data? I have some columns which are big but whose data are just short, and vice versa. I still need to resize them at run time. Thanks for the help.
Chris Eastwood
February 16th, 2000, 03:37 AM
You'll have to right-align those columns with numbers in (unless you want to subclass the custom-draw notification messages from the header - that's a lot of work). It may look ugly, but all the other programs that use a listview have the columns right aligned for numeric columns
If you want to automatically size the columns to fit the content (or the column header size) then you can use the following code in your form (changing ListView1 to the name of your listview) :
'
private Const LVM_FIRST = &H1000&
private Const LVSCW_AUTOSIZE = -1
private Const LVSCW_AUTOSIZE_USEHEADER = -2
private Const LVM_SETCOLUMNWIDTH = (LVM_FIRST + 30)
'
private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(byval hWnd as Long, byval lMsg as Long, byval wParam as Long, _
lParam as Any) as Long
'
private Sub AutoSizeListViewColumns()
Dim lCount as Long
'
for lCount = 1 to ListView1.ColumnHeaders.Count - 1
SendMessage ListView1.hWnd, LVM_SETCOLUMNWIDTH, lCount - 1, _
byval LVSCW_AUTOSIZE_USEHEADER
next
'
SendMessage ListView1.hWnd, LVM_SETCOLUMNWIDTH, _
ListView1.ColumnHeaders.Count - 1, byval LVSCW_AUTOSIZE_USEHEADER
'
End Sub
'
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb