Page 1 of 1

Posted: Tue Feb 06, 2007 11:12 am
by Shardik
Helpful to know:
Microsoft Knowledge Base Article ID 246364 wrote: SYMPTOMS
Sending a list view control an LVM_SETCOLUMNWIDTH message where the new width is set to LVSCW_AUTOSIZE or LVSCW_AUTOSIZE_USEHEADER will not work as expected for column 0 in report mode if an indent value is specified for any item.

CAUSE
The LVSCW_AUTOSIZE and LVSCW_AUTOSIZE_USEHEADER both are used to calculate the width of a column header based on either the header test and item text length. On COMMCTL32.DLL versions 4.70 and 4.72, the indent is not included in this calculation.

RESOLUTION
This has been fixed as of 5.80 of COMCTL32.dll. For versions prior to 5.80 the width of the column must be set by specifying a width in the lParam of the LVM_SETCOLUMNWIDTH message.
Code example for adjusting the width of column 0 or 1 of a ListIconGadget either to the column's header width or to the width of the column's widest column entry:

Code: Select all

If OpenWindow(0, 100, 100, 300, 160, "ListIcon adjust column width", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateGadgetList(WindowID(0))
    If LoadFont(0, "Verdana", 8, 0) 
      SetGadgetFont(#PB_Default, FontID(0)) ; Set the loaded Verdana 8 font as new standard
    EndIf 

    ListIconGadget(0, 5, 5, 290, 50, "Name", 50, #PB_ListIcon_AlwaysShowSelection)
    AddGadgetColumn(0, 1, "Test + test + test", 94)
    AddGadgetItem(0, -1, "Harry Rannit" + #LF$ + "12 Parliament")
    AddGadgetItem(0, -1, "Ginger Brokeit" + #LF$ + "130 PureBasic")
    ButtonGadget(1, 5, 60, 290, 20, "Adjust column 0 to header width")
    ButtonGadget(2, 5, 85, 290, 20, "Adjust column 0 to column width")
    ButtonGadget(3, 5, 110, 290, 20, "Adjust column 1 to header width")
    ButtonGadget(4, 5, 135, 290, 20, "Adjust column 1 to column width")

    If StartDrawing(WindowOutput(0)) 
      FontID = GetGadgetFont(0) 
      DrawingFont(FontID) 
      Column0HeaderWidth = TextWidth("Name") + 16
      StopDrawing()
    EndIf

    Repeat
      WindowEvent = WaitWindowEvent()

      If WindowEvent = #PB_Event_Gadget
        Select EventGadget()
          Case 1
            SendMessage_(GadgetID(0), #LVM_SETCOLUMNWIDTH, 0, Column0HeaderWidth)
          Case 2
            SendMessage_(GadgetID(0), #LVM_SETCOLUMNWIDTH, 0, #LVSCW_AUTOSIZE)
          Case 3
            SendMessage_(GadgetID(0), #LVM_SETCOLUMNWIDTH, 1, #LVSCW_AUTOSIZE_USEHEADER)
          Case 4
            SendMessage_(GadgetID(0), #LVM_SETCOLUMNWIDTH, 1, #LVSCW_AUTOSIZE)
        EndSelect
      EndIf
    Until WindowEvent = #PB_Event_CloseWindow
  EndIf
EndIf
If you adjust the last column of a ListIconGadget to its header width, be aware of this MSDN statement:
http://msdn.microsoft.com/library/defau ... nwidth.asp
MSDN wrote: LVSCW_AUTOSIZE_USEHEADER
Automatically sizes the column to fit the header text. If you use this value with the last column, its width is set to fill the remaining width of the list-view control.

Posted: Tue Feb 06, 2007 9:20 pm
by QuimV
:D Interesting,
Thanks Shardik