LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
Go Back  Xtreme Visual Basic Talk > > > LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected


Reply
 
Thread Tools Display Modes
  #1  
Old 12-01-2016, 08:56 PM
Dreamles Dancer Dreamles Dancer is offline
Freshman
 
Join Date: Mar 2008
Posts: 29
Default LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected


Using VB6 under windows 10.

I have these statements operating inside a loop:
Code:
    ListView_SetColumnWidth hListView, lvhIndex, LVSCW_AUTOSIZE
    lvFitContent = ListView_GetColumnWidth(hListView, lvhIndex) + IIf(lvhIndex = 0, 16, 0)
    ListView_SetColumnWidth hListView, lvhIndex, LVSCW_AUTOSIZE_USEHEADER
    lvFitHeader = ListView_GetColumnWidth(hListView, lvhIndex)

    If (MaxWidth = 0) Then
        lvhBestFit = IIf(lvFitContent > lvFitHeader, lvFitContent, lvFitHeader)
    Else
        lvhBestFit = IIf(MaxWidth < 1, lvFitHeader, MaxWidth)
    End If

    ListView_SetColumnWidth hListView, lvhIndex, lvhBestFit
When the listview is empty, this ought to resize the columns according to the width of the text in the header tabs, it don't. The columns appear to be set to a default minimum width. When the listview is populated, it also fails, and instead it's setting the listview columns according to the content. So my best guess is that the LVSCW_AUTOSIZE_USEHEADER is failing under windows 10.

If my surmise of the apparent behavior "bug" is correct, is there a means by which I can make this work?
__________________
Furcadia, an interesting online MMORPG in which you can create and program your own content.
Reply With Quote
  #2  
Old 12-03-2016, 08:21 PM
Dreamles Dancer Dreamles Dancer is offline
Freshman
 
Join Date: Mar 2008
Posts: 29
Default

Let us step this up a notch, it's failing to work with fixed numbers for the columns, ...
__________________
Furcadia, an interesting online MMORPG in which you can create and program your own content.
Reply With Quote
  #3  
Old 12-04-2016, 03:57 PM
Cerian Knight's Avatar
Cerian KnightLVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,194
Default

lvhIndex is 0-based, so subtract 1 from the actual column index before use. See here: https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

Tested your code (with above modification) on Windows 10 under various scaling sizes... works fine.

Not sure why SendMessage is remarked for ListView_SetColumnWidth here (?): Re: Listview resize

I removed remark and corrected bad line wraps before use of ListView.mod from that source.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').

Last edited by Cerian Knight; 12-04-2016 at 04:07 PM.
Reply With Quote
  #4  
Old 12-06-2016, 09:21 PM
Dreamles Dancer Dreamles Dancer is offline
Freshman
 
Join Date: Mar 2008
Posts: 29
Default

Code time, this is what I've been working with.

Code:
Attribute VB_Name = "win32api"
Option Explicit

Public Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" _
   (ByVal hWnd As Long, _
    ByVal Msg As Long, _
    ByVal wParam As Long, _
    lParam As Long) As Long

Public Const MAX_PATH As Long = 260

Public Const LVM_FIRST As Long = &H1000
Public Const LVM_GETCOLUMNWIDTH As Long = (LVM_FIRST + 29)
Public Const LVM_SETCOLUMNWIDTH  As Long = (LVM_FIRST + 30)
Public Const LVM_GETHEADER As Long = (LVM_FIRST + 31)
Public Const LVM_SETEXTENDEDLISTVIEWSTYLE As Long = (LVM_FIRST + 54)
Public Const LVM_GETEXTENDEDLISTVIEWSTYLE As Long = (LVM_FIRST + 55)

Public Const LVSCW_AUTOSIZE = -1
Public Const LVSCW_AUTOSIZE_USEHEADER = -2

Function ListView_GetHeader(ByVal hWnd As Long) As Long
    ListView_GetHeader = SendMessage(hWnd, LVM_GETHEADER, 0, 0)
End Function

Function ListView_GetColumnWidth(ByVal hWnd As Long, iCol As Long) As Long
    ListView_GetColumnWidth = SendMessage(hWnd, LVM_GETCOLUMNWIDTH, iCol, 0)
End Function

Function ListView_SetColumnWidth(ByVal hWnd As Long, ByVal iCol As Long, ByVal CX As Long) As Long
    ListView_SetColumnWidth = SendMessage(hWnd, LVM_SETCOLUMNWIDTH, iCol, CX)
End Function

Public Function ListView_SetExtendedListViewStyle(ByVal hwndLV As Long, ByVal DW As Long) As Long
    ListView_SetExtendedListViewStyle = SendMessage(hwndLV, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, DW)
End Function


Function Header_GetItemCount(ByVal hWndHD As Long) As Long
    Header_GetItemCount = SendMessage(hWndHD, HDM_GETITEMCOUNT, 0, 0)
End Function

' --- end Win32API stuff ---

Sub ResizeReportList(hListView As Long)
Dim hListHeader As Long
Dim lvhCount As Long, lvhIndex As Long
Dim dwReturn As Long, hWidth As Long
Dim lvRect As RECT, lvItemRect As RECT

    hListHeader = ListView_GetHeader(hListView)
    lvhCount = Header_GetItemCount(hListHeader)

' below was for reference and debugging
' no dice, columns still were not being sized correctly
'    For lvhIndex = 0 To lvhCount - 1
'        dwReturn = ListView_GetColumnWidth(hListView, lvhIndex)
'        dwReturn = ListView_SetColumnWidth(hListView, lvhIndex, 200)
'    Next lvhIndex

' Exit Sub

' below main loop to call on the next function which does, magic
    dwReturn = ResizeColumn(hListView, lvhIndex, 0)
    dwReturn = ListView_SetColumnWidth(hListView, 0, 50 + dwReturn)
    For lvhIndex = 1 To lvhCount - 2
        dwReturn = ResizeColumn(hListView, lvhIndex, 0)
    Next lvhIndex

End Sub

' meaty function, calculates on whether it should size a column based
' on column of the header if content too narrow
' or on width of content

Function ResizeColumn(hListView As Long, lvhIndex As Long, MaxWidth As Long) As Long
Dim lvFitHeader As Long, lvFitContent As Long, lvhBestFit As Long
Dim Work  As String

    ListView_SetColumnWidth hListView, lvhIndex, LVSCW_AUTOSIZE
    lvFitContent = ListView_GetColumnWidth(hListView, lvhIndex) + IIf(lvhIndex = 0, 16, 0)
    ' ListView_SetColumnWidth hListView, lvhIndex, LVSCW_AUTOSIZE_USEHEADER
    lvFitHeader = ListView_GetColumnWidth(hListView, lvhIndex)

    If (MaxWidth = 0) Then
        lvhBestFit = IIf(lvFitContent > lvFitHeader, lvFitContent, lvFitHeader)
    Else
        lvhBestFit = IIf(MaxWidth < 1, lvFitHeader, MaxWidth)
    End If

    ListView_SetColumnWidth hListView, lvhIndex, lvhBestFit
    ResizeColumn = lvhBestFit

End Function
__________________
Furcadia, an interesting online MMORPG in which you can create and program your own content.
Reply With Quote
  #5  
Old 12-08-2016, 10:09 AM
Cerian Knight's Avatar
Cerian KnightLVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,194
Default

Added the HDM Constants and RECT Type to your module.
Added 'hListView = ListView1.hWnd' and 'lvhIndex = 0' to the beginning of your original form code.
Changed ListView_SetColumnWidth function code in module to use ByVal:
ListView_SetColumnWidth = SendMessage(hWnd, LVM_SETCOLUMNWIDTH, iCol, ByVal CX)
See here: Listview Auto column resizing

Seems to work fine, now.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').

Last edited by Cerian Knight; 12-08-2016 at 04:32 PM. Reason: minor clean-up
Reply With Quote
  #6  
Old 12-11-2016, 12:59 PM
Dreamles Dancer Dreamles Dancer is offline
Freshman
 
Join Date: Mar 2008
Posts: 29
Default

ListView_SetColumnWidth = SendMessage(hWnd, LVM_SETCOLUMNWIDTH, iCol, ByVal CX)

That's what I was missing!

Thank you very, very much.

P.S. The other suggestions are being implemented in other parts of the overall program.
__________________
Furcadia, an interesting online MMORPG in which you can create and program your own content.
Reply With Quote
Reply

Tags
lvhindex, lvfitheader, listview_setcolumnwidth, hlistview, lvhbestfit, lvscw_autosize_useheader, listview, columns, maxwidth, lvfitcontent, fails, windows, content, populated, setting, guess, means, correct, bug, tabs, failing, surmise, behavior, apparent, text


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
 
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
LVSCW_AUTOSIZE_USEHEADER Fails To Work As Expected
 
-->