Add icon\image to ListView in other column

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Add icon\image to ListView in other column

25 Jun 2017, 09:30

Hii,

Ive got this code which have icon added to the 1st column of the listview,
however i cant figure out how to add the icon to other column except the 1st column.

how can i add the icon to the 2nd column for expample?

Code: Select all

Gui, Add, ListView, grid h50 w310, Icon|Icon2?
ImageListID := IL_Create()
LV_SetImageList(ImageListID)
IL_Add(ImageListID, "C:\Windows\System32\PerfCenterCpl.ico")
LV_Add("Icon" 1,, "in this column i want the same icon to be shown aswell")
Gui, Show
return

esc::
GuiClose:
ExitApp

Thanks in advance!
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: Add icon\image to ListView in other column

27 Jun 2017, 05:24

Thanks as always just me,
i will notify you if ill get troubles :D
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: Add icon\image to ListView in other column

28 Jun 2017, 03:43

what i do wrong ?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#Include LV_EX.ahk

Gui, Add, ListView, grid hwndHLV h80 w310, Icon|Icon2?
ImageListID := IL_Create()
LV_SetImageList(ImageListID)
IL_Add(ImageListID, "C:\Windows\System32\PerfCenterCpl.ico")
LV_Add("Icon" 1,, "in this column i want the same icon to be shown aswell")

; Failed to add the same icon also to the 2nd column
LV_EX_SetSubitemImage(HLV, 2, 2, IL_Add(ImageListID, "C:\Windows\System32\PerfCenterCpl.ico"))

Gui, Show
return

esc::
GuiClose:
ExitApp

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

Re: Add icon\image to ListView in other column

28 Jun 2017, 04:29

LV_EX_SetSubItemImage() has 4 parameters:
  • HLV - the handle (HWND) of the ListView
  • Row - the 1-based row number
  • Column - the 1-based column number
  • Index - the 1-based index of the icon in the ListView's small ImageList (as used as "IconIndex" in LV_Add()).

Code: Select all

LV_EX_SetSubitemImage(HLV, 2, 2, IL_Add(ImageListID, "C:\Windows\System32\PerfCenterCpl.ico"))
I your example you add only one row to the ListView. So why do you specify 2 for the row number? This row doesn't exist, so how could an icon be added?

Also, you don't need to add an existing icon again (IL_Add(ImageListID, "C:\Windows\System32\PerfCenterCpl.ico")). Use the icon's inex 1 as you did in LV_Add() in this case. Otherwise this would be a valid option.
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: Add icon\image to ListView in other column

29 Jun 2017, 01:08

Thanks just me
this my result, it works and i hope its the correct way now

Code: Select all


#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#Include LV_EX.ahk

Gui, Add, ListView, grid hwndHLV h80 w310, Icon|Icon2|Icon3|Icon4
ImageListID := IL_Create()
LV_SetImageList(ImageListID)
IL_Add(ImageListID, "C:\Windows\System32\PerfCenterCpl.ico")
LV_EX_SetSubitemImage(HLV, 1, 2, LV_Add("Icon" 1,, ""))
Gui, Show
return

esc::
GuiClose:
ExitApp

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

Re: Add icon\image to ListView in other column

29 Jun 2017, 01:21

No, it isn't!

Code: Select all

LV_EX_SetSubitemImage(HLV, 1, 2, LV_Add("Icon" 1,, ""))
LV_Add("Icon" 1,, "") returns a row number whereas the last parameter of LV_EX_SetSubitemImage() must be an icon number.

Code: Select all

Row := LV_Add("Icon" 1,, "") ; uses icon 1
LV_EX_SetSubitemImage(HLV, Row, 2, 1) ; ditto
or shorter

Code: Select all

LV_EX_SetSubitemImage(HLV, LV_Add("Icon" 1,, ""), 2, 1)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: hedehede81, ht55cd3, OrangeCat and 325 guests