AutoFit a listview column programmatically? 
Author Message
 AutoFit a listview column programmatically?

Hi.

I know you can double-click on a ListView column (or it's right hand side)
to automatically fit the column to it's widest item.

I'm using VB6. How can I do this programmatically?

Thanks.

Alastair



Wed, 17 Jul 2002 03:00:00 GMT  
 AutoFit a listview column programmatically?


Quote:
>Hi.

>I know you can double-click on a ListView column (or it's right hand side)
>to automatically fit the column to it's widest item.

>I'm using VB6. How can I do this programmatically?

>Thanks.

>Alastair

Alastair,

Const LVM_FIRST As Long = &H1000
Const LVM_SETCOLUMNWIDTH As Long = LVM_FIRST + 30
Const LVSCW_AUTOSIZE_USEHEADER = -2

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

Private Sub SizeColumns(LV As ListView)
    Dim Column As Long
    For Column = 0 To LV.ColumnHeaders.Count - 1
       SendMessage LV.hwnd, LVM_SETCOLUMNWIDTH, _
       Column, LVSCW_AUTOSIZE_USEHEADER
    Next
End Sub

Private Sub SizeColumn(LV As ListView, Optional ByVal Col as Long = 0)
       SendMessage LV.hwnd, LVM_SETCOLUMNWIDTH, _
       Col, LVSCW_AUTOSIZE_USEHEADER
End Sub

Jon
--
Avoid cleaning your mouse rollers whilst using RegEdit



Thu, 18 Jul 2002 03:00:00 GMT  
 AutoFit a listview column programmatically?


Quote:


>>Hi.

>>I know you can double-click on a ListView column (or it's right hand side)
>>to automatically fit the column to it's widest item.

>>I'm using VB6. How can I do this programmatically?

>>Thanks.

>>Alastair

Alastair,

Got carried away with my prev msg and hit a few too many keys, replace
all occurrences of the Const:

Public Const LVSCW_AUTOSIZE_USEHEADER = -2

with this:

Public Const LVSCW_AUTOSIZE = -1

Jon
--
Avoid cleaning your mouse rollers whilst using RegEdit



Thu, 18 Jul 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Autofit ListView column width with double-click (event?)

2. ListView - Expanding Column Widths programmatically

3. Programmatically Changing Listview Column

4. DataGrid Setting Width of Columns to Fit Autofit.

5. Setting column autofit in Excel using VBA

6. DataGrid Column Autofit Problem!!

7. ListView column (not column content) order

8. ListView column width = ListView width ?

9. How to set programmatically set values of custom added columns

10. Programmatically loop through columns of a table in a database model

11. format with multiple columns programmatically

12. Olap Select Rows/Columns Members Programmatically

 

 
Powered by phpBB® Forum Software