GUI Pop a new field if a specific dropdownlist item is selected Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LlamaNoHat
Posts: 17
Joined: 18 Apr 2022, 09:38

GUI Pop a new field if a specific dropdownlist item is selected

Post by LlamaNoHat » 16 May 2022, 11:41

Hello,

Is it possible to add a field into a GUI only if a specific item from the dropdown list is selected?

For example:

Code: Select all

Colors := ["Red|Blue|Green|Other"]
List := Colors1

Gui, Add, Text, x12 y19 w110 h20 , Color name:
Gui, Add, DropDownList,R10 x12 y49 w180 h10 vDropDown,% List  

DropDown:
???
 Loop, %List%
      If ("Other")
      {
	Gui, Add, Text, x12 y79 w110 h20 , SPECIFY:
        Gui, Add, Edit, x12 y109 w110 h20 vSPECIFY,% ""
      } else {
	Continue
}
Return

]

User avatar
mikeyww
Posts: 26875
Joined: 09 Sep 2014, 18:38

Re: GUI Pop a new field if a specific dropdownlist item is selected

Post by mikeyww » 16 May 2022, 13:31

To select an item from the list, you will need to show the GUI first. After you then submit the GUI, you can use GuiControl to alter it.

LlamaNoHat
Posts: 17
Joined: 18 Apr 2022, 09:38

Re: GUI Pop a new field if a specific dropdownlist item is selected

Post by LlamaNoHat » 16 May 2022, 15:12

Hi,

Maybe I explained what I need incorrectly, or perhaps I misunderstood you.

What I meant to say is I have a fully functional GUI based app, in which I can enter data and save it into a file for later use. However, having an addition as follows would reduce the manual work that needs to be done afterwards in the file itself:

There is a dropdown list with Names (like colors), a field for qty., and two more fields for other information. However, if the color "Other" is selected from the dropdown, I want this selection summon an additional field in which the user can enter information about the selected item. At the end during the file append those lines that have "Other" selected would also have an additional column specifying according to user.

I don't need this field to always be active, since it is not required for other data lines, however, specifically for the "Other" dropdown selection I need it to come up to be usable until the user changes the dropdown selection to something else, which would again hide the additional field.

User avatar
mikeyww
Posts: 26875
Joined: 09 Sep 2014, 18:38

Re: GUI Pop a new field if a specific dropdownlist item is selected  Topic is solved

Post by mikeyww » 16 May 2022, 16:56

Code: Select all

Gui, Font, s10
Gui, Add, Text        ,                     , Color name:
Gui, Add, DropDownList, w300 vsel    gCheck , Red|Blue|Green|Other
Gui, Add, Edit        , wp   vdetail Hidden
Gui, Add, Button      , wp           Default, OK
Gosub, F3
F3::
GuiControl,, detail
Gui, Show,, Colors (F3 = show again)
Return

Check:
Gui, Submit, NoHide
GuiControl, % (sel = "Other") ? "Show" : "Hide", detail
Return

ButtonOK:
Gui, Submit
MsgBox, 64, Selection, %sel%`n`n%detail%
Return

LlamaNoHat
Posts: 17
Joined: 18 Apr 2022, 09:38

Re: GUI Pop a new field if a specific dropdownlist item is selected

Post by LlamaNoHat » 17 May 2022, 10:50

mikeyww wrote:
16 May 2022, 16:56

Code: Select all

Gui, Font, s10
Gui, Add, Text        ,                     , Color name:
Gui, Add, DropDownList, w300 vsel    gCheck , Red|Blue|Green|Other
Gui, Add, Edit        , wp   vdetail Hidden
Gui, Add, Button      , wp           Default, OK
Gosub, F3
F3::
GuiControl,, detail
Gui, Show,, Colors (F3 = show again)
Return

Check:
Gui, Submit, NoHide
GuiControl, % (sel = "Other") ? "Show" : "Hide", detail
Return

ButtonOK:
Gui, Submit
MsgBox, 64, Selection, %sel%`n`n%detail%
Return
Thank you. I do have one more silly question for which I am probably not looking well enough in the documentation. Is there a way to specify two references in sel = "_" so that the new field would appear when either one or the other reference is selected?
I've tried:
sel = "Other", "Red"
sel = "Other"|"Red"
Select1 := Other
Select 2 := Red
sel := %Other%|%Red%

however, none seem to work. I've also tried repeating the same lines with a new selection reference, however, the app responds only to the last written selection and pops a field for that, not for the other.
I'm probably going crazy here missing something small....

User avatar
mikeyww
Posts: 26875
Joined: 09 Sep 2014, 18:38

Re: GUI Pop a new field if a specific dropdownlist item is selected

Post by mikeyww » 17 May 2022, 11:31

Code: Select all

If sel in Blue,Other
     GuiControl, Show, detail
Else GuiControl, Hide, detail

Code: Select all

If (sel = "Other" || sel = "Blue")
     GuiControl, Show, detail
Else GuiControl, Hide, detail

Post Reply

Return to “Ask for Help (v1)”