Results 1 to 4 of 4

Thread: How to resize the listview column header?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    How to resize the listview column header?

    What's the easiest way to resize each listview column according to the width of the data in them. Thanks in advance.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: How to resize the listview column header?

    I use the following function to resize my listview columns.

    Code:
    Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" ( _
                   ByVal hWnd As Long, _
                   ByVal wMsg As Long, _
                   ByVal wParam As Long, _
                   lParam As Long) As Long
    Public Const LVM_FIRST                  As Long = &H1000
    
    Public Sub LVAutoSizeColumn(lv As ListView, Optional Column As ColumnHeader = Nothing)
        Dim c As ColumnHeader
        ''Should only resize those with items
        If lv.ListItems.Count > 0 Then
            If Column Is Nothing Then
                For Each c In lv.ColumnHeaders
                    SendMessage lv.hWnd, LVM_FIRST + 30, c.Index - 1, -1
                Next
            Else
                SendMessage lv.hWnd, LVM_FIRST + 30, Column.Index - 1, -1
            End If
            lv.Refresh
        End If
    End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to resize the listview column header?

    I use VB 6. I got error at this line..It said not define..

    Public Sub LVAutoSizeColumn(lv As ListView, Optional Column As ColumnHeader = Nothing)

    Also at this line, I got error

    Public Const LVM_FIRST As Long = &H1000

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: How to resize the listview column header?

    If you are declaring it in your form then you have to make it Private instead. Could you specify the complete error description in LVAutoSizeColumn?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width