Access to ListView data from Button subroutine? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Access to ListView data from Button subroutine?

17 Jul 2018, 04:08

I'm trying to understand how ListView actually work. Below you could see the code. For some reason, when I press button, it doesn't show me the name of selected file. Intead, it shows me the header of first column. How to fix it?

Code: Select all

Gui, Add, ListView, r20 w500 gMyListView, Name|Size (KB)
Loop, %A_Desktop%\*.*
    LV_Add("", A_LoopFileName, A_LoopFileSizeKB)
LV_ModifyCol()
LV_ModifyCol(2, "Integer")
Gui, Add, Button, gShowName, Show Name
Gui, Show
return

MyListView:
if (A_GuiEvent = "DoubleClick")
{
    LV_GetText(RowText, A_EventInfo)
    MsgBox, %RowText% ; Works fine
}
return

GuiClose:
ExitApp

ShowName:
    LV_GetText(RowText, A_EventInfo)
    MsgBox, %RowText% ; Doesn't properly work
return
Last edited by john_c on 17 Jul 2018, 04:37, edited 1 time in total.
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: Access to ListView data from Button subroutine?  Topic is solved

17 Jul 2018, 04:34

Hello John_c
The A_EventInfo is only available for the listview item, try this

Code: Select all


ShowName:
RowNumber = 0
Loop   {
 RowNumber := LV_GetNext(RowNumber)  
 If (!RowNumber)
    Break
 LV_GetText(Text, RowNumber)
 MsgBox % Text
 }
Return
Donec Perficiam
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Re: Access to ListView data from Button subroutine?

17 Jul 2018, 04:56

Thank you very much, it works. (Probably there are another solutions for this task, but this one works for me).
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: Access to ListView data from Button subroutine?

17 Jul 2018, 05:08

We all do what we can and we know, if it works, it's perfect :bravo:
Donec Perficiam
garry
Posts: 3764
Joined: 22 Dec 2013, 12:50

Re: Access to ListView data from Button subroutine?

22 Jul 2018, 07:32

@jmeneses, thank you
lately, just another example

Code: Select all

Gui, Add, ListView, r20 w500 gMyListView vLV, Name|Size (KB)
Loop, %A_Desktop%\*.*
    LV_Add("", A_LoopFileName, A_LoopFileSizeKB)
LV_ModifyCol()
LV_ModifyCol(2, "Integer")
Gui, Add, Button, gShowName, Show Name
Gui, Show
return
MyListView:
if (A_GuiEvent = "DoubleClick")
{
    LV_GetText(RowText, A_EventInfo)
    MsgBox, %RowText% ; Works fine
}
return
GuiClose:
ExitApp

ShowName:
Gui,1:ListView, LV1
;RC:=LV_GetNext("C")    ;- also OK
RF:=LV_GetNext("F")
if (rf=0)
  return
LV_GetText(Text, RF)
MsgBox % Text
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ArkuS, Google [Bot], mikeyww and 329 guests