Column width of List view 
Author Message
 Column width of List view

I want to know how to automatic set the column width of List View according
the data length display

--
Best Regards,

Eric Yum



Mon, 16 Aug 2004 11:52:36 GMT  
 Column width of List view


Quote:
> I want to know how to automatic set the column width of List View
according
> the data length display

You need to send a message to the ListView control...specifically, the
LVM_SETCOLUMNWIDTH message, repeated for each column.  Here's sample code.

Private Const LVM_FIRST                                             As Long
= &H1000
Private Const LVM_SETCOLUMNWIDTH                    As Long = LVM_FIRST + 30
Private Const LVSCW_AUTOSIZE                                As Long = -1
Private Const LVSCW_AUTOSIZE_USEHEADER        As Long = -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

#If VB6 Then
    Public Sub AutoSizeLVColumns(oLV As MSComctlLib.ListView, Optional ByVal
bUseHeader As Boolean = True)
#Else
    Public Sub AutoSizeLVColumns(oLV As ComctlLib.ListView, Optional ByVal
bUseHeader As Boolean = True)
#End If

    Dim lColumnIndex As Long

    For lColumnIndex = 0 To oLV.ColumnHeaders.Count - 1
        If bUseHeader Then
            Call SendMessage(oLV.hwnd, LVM_SETCOLUMNWIDTH, lColumnIndex,
ByVal LVSCW_AUTOSIZE_USEHEADER)
        Else
            Call SendMessage(oLV.hwnd, LVM_SETCOLUMNWIDTH, lColumnIndex,
ByVal LVSCW_AUTOSIZE)
        End If
    Next

End Sub

If you specify True for bUseHeader, the column will size based on the text
in the ColumnHeader; otherwise, it will size the columns based on the
longest text within that column.

Mike



Mon, 16 Aug 2004 13:16:53 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Column width of List view

2. Display Bitmaps in Sub Items and column Headers of List View During Report View

3. List View Column - - Possible items in a Single Column

4. List View Width and Scroll Question

5. Column Width in List mode (Listview control)

6. How to change the column width of a multi-line list box

7. How to change the column width of a multi-line list box

8. Setting datagrid column width sets width of toplevel!!

9. Set Grid width to sum of Column Widths

10. ListView column width = ListView width ?

11. Total width of columns = Width of ListView

12. Total width of columns = Width of ListView

 

 
Powered by phpBB® Forum Software