DropDownList undocumented behaviour

Report problems with documented functionality
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

DropDownList undocumented behaviour

27 May 2019, 01:47

https://autohotkey.com/docs/commands/GuiControls.htm#DropDownList wrote:When the Gui Submit command is used, the control's associated output variable (if any) receives the text of the currently selected item.

But it should also mention the output variable receives the item's text before the Gui Submit command is used, if the user is hovering the mouse over a DDL item.

This was causing some strange behaviour in my script where I have a timer which does things based on the value of the drop down list's var, which requires some code from the DDL's gsub to execute in order to be consistent with the rest of my script, which never gets executed during that moment when the user is hovering over the DDL items.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: DropDownList undocumented behaviour

27 May 2019, 02:30

The associated variable of a control is only assigned a value at these times:
  • When Gui Submit is called.
  • For ActiveX, when you create the control.
  • For several control types (not including DDL), immediately prior to execution of the g-label.
  • When the script explicitly assigns to it (or uses it as an output variable).
What you describe does not happen.
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: DropDownList undocumented behaviour

27 May 2019, 03:07

Code: Select all

Gui , Main: New
Gui , Add , DropDownList , vDropDownList w150, One||Two|Three
Gui , Add , Text , vText xp+180 w150 , vDropDownList: 
Gui , Show , Center
SetTimer , GetDDL , 250
return

GetDDL:
GuiControlGet , CurrVal , Main:, DropDownList
GuiControl , Main: , Text , vDropDownList: %CurrVal%
return

Image


lexikos wrote:
27 May 2019, 02:30
When the script explicitly assigns to it (or uses it as an output variable).
True, and this is what the above code does, but I still think it's worth documenting that the value assigned is equal to whatever the mouse happens to be hovering over, not the value which the DDL is currently set to.
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: DropDownList undocumented behaviour

27 May 2019, 03:31

lexikos wrote:
27 May 2019, 02:30
When the script explicitly assigns to it (or uses it as an output variable)

On further consideration, this isn't actually what my code does, because GuiControlGet uses the output variable CurrVal, not DropDownList, nor does it explicitly assign to DropDownList.
just me
Posts: 9451
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DropDownList undocumented behaviour

27 May 2019, 04:46

Why do you want to use a timer to check if the selection in the DropDownList has changed? That's a task for a g-label:

Code: Select all

#NoEnv
Gui , Main: New
Gui , Add , DropDownList , gDDLChanged vDropDownList w150, One||Two|Three
GuiControlGet , DropDownList
Gui , Add , Text , vText xp+180 w150 , vDropDownList: %DropDownList%
Gui , Show , Center
Return

MainGuiClose:
ExitApp

DDLChanged:
GuiControlGet , DropDownList 
GuiControl , , Text , vDropDownList: %DropDownList%
Return
With your timer, you are explicitly querying the control for the current selection. The ListBox as part of a DropDownList control seems to provide the selection currently shown (the item the mouse is hovering on).
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: DropDownList undocumented behaviour

27 May 2019, 07:05

just me wrote:
27 May 2019, 04:46
Why do you want to use a timer to check if the selection in the DropDownList has changed? That's a task for a g-label

Unfortunately I have some cases where I can't do that because the DDL selection controls some things external to the application which could change and needs to be enforced with a timer. My workaround was to just store a second copy of the DDL's var inside its g-label, which only gets updated when the user left-clicks the DDL selection.

edit: on further consideration my timer doesn't need to use Gui Submit or GuiControlGet, so it shouldn't be an issue.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 44 guests