Results 1 to 2 of 2

Thread: Listiview - width and text

  1. #1

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    Question

    Hi

    How I increment a column of the listview, I set the property width with 1000 , but the text that I put do not fill all column:
    How do I for the text all be no listview ?

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    If I understand you correctly, you want to resize a ListView based on the text in it. The easiest way to do it is to use SendMessage API. Here is a little example:
    Code:
    Option Explicit
    
    Private Const LVM_FIRST As Long = 4096
    Private Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30)
    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
    
    
    Private Sub Form_Load()
        Dim itmListItem As ListItem
        Dim i As Integer
        Dim j As Integer
        
        With ListView1
            .ColumnHeaders.Add , , "Column1"
            .ColumnHeaders.Add , , "Column2"
            .ColumnHeaders.Add , , "Column3"
            .ColumnHeaders.Add , , "Column4"
            
            For i = 1 To 10
                Set itmListItem = .ListItems.Add(, "Item" & i, "Item" & i)
                For j = 1 To .ColumnHeaders.Count - 1
                    itmListItem.SubItems(j) = "SubItem with long text " & i & j
                Next
            Next
        End With
    End Sub
    
    
    Private Sub Command1_Click()
        Dim intCol As Integer
        
        With ListView1
            For intCol = 0 To .ColumnHeaders.Count - 1
                Call SendMessage(.hwnd, LVM_SETCOLUMNWIDTH, intCol, ByVal LVSCW_AUTOSIZE_USEHEADER)
            Next
        End With
    End Sub
    By clicking the button, ListView will be resized according the text in it.

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