Order of columns in a list-view Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
d1niel84
Posts: 51
Joined: 20 Oct 2019, 12:28
Location: Germany

Order of columns in a list-view

Post by d1niel84 » 06 Oct 2022, 13:33

I tried the LV_Ex sample from viewtopic.php?t=1256 with the LV_EX_SetColumnOrder function.
But it was not possible to change the order. Anyone knows how to fix this?

Code: Select all

#NoEnv
#Include LV_EX.ahk
; ----------------------------------------------------------------------------------------------------------------------
   ; From the help file:
   HIML := IL_Create(10)  ; Create an ImageList to hold 10 small icons.
   Loop 10  ; Load the ImageList with a series of icons from the DLL.
       IL_Add(HIML, "shell32.dll", A_Index)  ; Omits the DLL's path so that it works on Windows 9x too.
   BkgImages := []
   Loop, %A_WinDir%\Web\Wallpaper\*.jpg, 0, 1
      BkgImages.Insert(A_LoopFileFullPath)
   Rows := 20
   Gui, Margin, 20, 20
   Gui, Add, Button, ym gOrder123, Order 1, 2, 3
   Gui, Add, Button, ym gOrder321, Order 3, 2, 1
   Gui, Add, Button, ym gRemoveImage, Remove BkImage
   Gui, Add, Button, ym gNewImage, New BkImage
   Gui, Add, Text, xm Section h20, First visible row:
   Gui, Add, Text, hp y+0, Is row 20 visible?
   Gui, Add, Text, hp y+0, Number of visible rows:
   Gui, Add, Text, ys hp vFVR, 00
   Gui, Add, Text, hp y+0 vIRV, 00
   Gui, Add, Text, hp y+0 vNOVR, 00
   Gui, Add, Button, ys gCheck, New Check
   Gui, Add, Listview, xm w500 r10 Grid cWhite hwndHLV vVLV, Col 1|Col 2|Col 3|Icon ; add -LV0x20 on Win XP
   LV_SetImageList(HIML)
   Loop, %Rows% {
      Zeroes := SubStr("000", 1, 3 - StrLen(A_Index))
      LV_Add("Icon0", "A" . Zeroes . A_Index, "B" . Zeroes . A_Index, "C" . Zeroes . A_Index)
   }
   Loop, %Rows%   ; put a random icon into column 4
      LV_EX_SetSubitemImage(HLV, A_Index, 4, Mod(A_Index, 10) + 1)
   Columns := LV_GetCount("Column")
   Loop, % Columns
      LV_ModifyCol(A_Index, "AutoHdr")
   Random, Index, 1, % BkgImages.MaxIndex()
   LV_EX_SetBkImage(HLV, BkgImages[Index])
   GoSub, Check
   Gui, Show, , LV_EX sample
Return
; ----------------------------------------------------------------------------------------------------------------------
Order123:
   GuiControl, -ReDraw, %HLV%
   LV_EX_SetColumnOrder(HLV, [1, 2, 3])
   ColArr := LV_EX_GetColumnOrder(HLV)
   For Each, I In ColArr
      LV_ModifyCol(I, "AutoHdr")
   GuiControl, +ReDraw, %HLV%
Return
; ----------------------------------------------------------------------------------------------------------------------
Order321:
   GuiControl, -ReDraw, %HLV%
   LV_EX_SetColumnOrder(HLV, [3, 2, 1])
   ColArr := LV_EX_GetColumnOrder(HLV)
   For Each, I In ColArr
      LV_ModifyCol(I, "AutoHdr")
   GuiControl, +ReDraw, %HLV%
Return
; ----------------------------------------------------------------------------------------------------------------------
Check:
   GuiControl, , FVR,  % LV_EX_GetTopIndex(HLV)
   GuiControl, , IRV,  % LV_EX_IsRowVisible(HLV, 20)
   GuiControl, , NOVR, % LV_EX_GetRowsPerPage(HLV)
Return
; ----------------------------------------------------------------------------------------------------------------------
NewImage:
   GuiControl, -ReDraw, %HLV%
   Random, Index, 1, % BkgImages.MaxIndex()
   LV_EX_SetBkImage(HLV, BkgImages[Index])
   GuiControl, +ReDraw, %HLV%
   GuiControl, Focus, %HLV%
Return
; ----------------------------------------------------------------------------------------------------------------------
RemoveImage:
   GuiControl, -ReDraw, %HLV%
   LV_EX_SetBkImage(HLV, "")
   GuiControl, +ReDraw, %HLV%
   GuiControl, Focus, %HLV%
Return
; ----------------------------------------------------------------------------------------------------------------------
GuiClose:
ExitApp

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: Order of columns in a list-view  Topic is solved

Post by flyingDman » 06 Oct 2022, 14:00

You need to list the 4 columns in the array. For example replace line 52 with this: LV_EX_SetColumnOrder(HLV, [3,2,1,4])
14.3 & 1.3.7

d1niel84
Posts: 51
Joined: 20 Oct 2019, 12:28
Location: Germany

Re: Order of columns in a list-view

Post by d1niel84 » 06 Oct 2022, 15:33

flyingDman wrote:
06 Oct 2022, 14:00
You need to list the 4 columns in the array. For example replace line 52 with this: LV_EX_SetColumnOrder(HLV, [3,2,1,4])
Perfect, thanks that makes sense.I was always focused on the 1,2,3 in the header

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Order of columns in a list-view

Post by just me » 07 Oct 2022, 03:45

@d1niel84:

Sorry, I fixed the sample script years ago but obviously never transferred the change to GitHub. I did it right now.

Post Reply

Return to “Ask for Help (v1)”