right click on Listbox

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

right click on Listbox

31 Dec 2018, 02:51

How do I get the text from a row in a listbox by right-clicking on it? This script only retrieves the row number, but not its text. I have been hammering away at this for an hour and I finally give up :(

Code: Select all

Gui, Add, Listbox, x50 y50 gGuiContextMenu, This is Row 1|This is Row 2|This is Row 3
Gui, Show, h200 w200
return

guiclose:
exitapp

GuiContextMenu:
if A_GuiEvent = RightClick
{
	msgbox, %A_EventInfo%
}
return
scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

Re: right click on Listbox

31 Dec 2018, 03:14

nevermind, I figured it out :)

Code: Select all

Gui, Add, Listbox, x50 y50 gGuiContextMenu, This is Row 1|This is Row 2|This is Row 3
Gui, Show, h200 w200
return

guiclose:
exitapp

GuiContextMenu:
Gui, Submit, NoHide
if A_GuiEvent = RightClick
{
ControlGet, TextVar, Choice,, %focusvar%
msgbox, you right-clicked on %textvar%
}
return
just me
Posts: 9495
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: right click on Listbox

31 Dec 2018, 03:25

Code: Select all

#NoEnv
Gui, Add, Listbox, x50 y50 w300 vMyList, This is Row 1|This is Row 2|This is Row 3 ; gGuiContextMenu <--- will be called automatically for a right-click
Gui, Show, , ListBox Test
Return

GuiClose:
ExitApp

GuiContextMenu:
If (A_GuiControl = "MyList") && (A_GuiEvent = "RightCLick")
{
   GuiControlGet, MyList
   MsgBox, 0, MyList, Currently selected item: %MyList%
}
Return
scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

Re: right click on Listbox

31 Dec 2018, 04:10

thanks justme! its always great to have a few different approaches - I will save your code for future reference - actually, I think yours is much better now that I look at it :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, haomingchen1998 and 130 guests