Refreshing / GuiControl for Dropdownlist Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Peter2
Posts: 325
Joined: 21 Sep 2014, 14:38
Location: CH

Refreshing / GuiControl for Dropdownlist

Post by Peter2 » 06 Dec 2022, 07:13

I'm fizzling around, sometimes it works, sometimes not - I miss the basic understanding ..
----------------
I have a Dropdownlist, filled with values from variable "mylist" with A,b,c, d.
A subroutines changes "mylist" - sometimes it contains only a, b; then a,c, d ...
After every call of my subroutine I want to display the new values of "mylist"

Problem:
Sometimes it is displayed correctly, sometimes it merges with the old values, so "old a,b,c,d" plus "new a,b" results in displayed "a,a,b,b,c,d"

Simple question:
How (and what?) reset and refresh the GUI?

Thanks for help!
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33

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

Re: Refreshing / GuiControl for Dropdownlist

Post by mikeyww » 06 Dec 2022, 07:28

If we should be guessing what is in the script at this point, the following passage may help.

GuiControl:
Tab/DropDownList/ComboBox/ListBox: Value should contain a pipe-delimited list of entries to be appended at the end of the control's list. To replace (overwrite) the list instead, include a pipe as the first character (e.g. |Red|Green|Blue). To make the control empty, specify only a pipe character (|). To have one of the entries pre-selected, include two pipes after it (e.g. Red|Green||Blue). The separator between fields may be changed to something other than pipe. For example, Gui +Delimiter`n would change it to linefeed and Gui +DelimiterTab would change it to tab (`t).

Peter2
Posts: 325
Joined: 21 Sep 2014, 14:38
Location: CH

Re: Refreshing / GuiControl for Dropdownlist

Post by Peter2 » 06 Dec 2022, 08:32

Thansk @mikeyww
this is what I already found.
mikeyww wrote:
06 Dec 2022, 07:28
GuiControl:
...To make the control empty, specify only a pipe character (|). ....
What does "specify" means?
- to set the variable or
- to use "GuiControl"
- or both of it?
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33

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

Re: Refreshing / GuiControl for Dropdownlist  Topic is solved

Post by mikeyww » 06 Dec 2022, 08:38

"Specify" means that this is how you use a parameter with the GuiControl command. It means "indicate" or "provide". An example of "specify" would be, "Authors of forum posts should specify their script when they create a new post."

Code: Select all

list = Black|White|Red|Green|Blue
Gui, Font, s10
Gui, Add, DropDownList, w250 vsel
Gui, Add, Button      , wp   Default, Update
Gui, Show,, Colors
updateDDL(list)
Return

ButtonUpdate:
GuiControl, Hide, Update
list = Magenta|Orange|Purple
updateDDL(list)
Return

updateDDL(list) {
 GuiControl,, sel, % "|" StrReplace(Trim(list, "|"), "|", "||",, 1)
}
Or:

Code: Select all

list = Black|White|Red|Green|Blue
Gui, Font, s10
Gui, Add, DropDownList, w250 vsel
Gui, Add, Button      , wp   Default, Update
Gui, Show,, Colors
update(list)
Return

ButtonUpdate:
GuiControl, Hide, Update
list := update(list, "Black", "Magenta", "White", "Purple")
Return

update(list, add*) {
 list := Trim(list, "|")
 For each, item in add
  (!Instr("|" list "|", "|" item "|")) && list := item "|" list
 GuiControl,, sel, % "|" StrReplace(list, "|", "||",, 1)
 Return list
}

Peter2
Posts: 325
Joined: 21 Sep 2014, 14:38
Location: CH

Re: Refreshing / GuiControl for Dropdownlist

Post by Peter2 » 06 Dec 2022, 09:30

mikeyww wrote:
06 Dec 2022, 08:38
... "Authors of forum posts should specify their script when they create a new post."..
Yes, of course. But I think my code is on a low level which makes more confusion than information.

But I think in the meantime I found a way (I hope the right one). I had some confusion with the value of the variable and the calling of the control and using of the pipes. Here is now the famous code snippet - which finally is rather trivial..

Code: Select all

; set variable to blank
        zeigeliste = 
; modify it (add more strings to it)
        Loop, Parse, jobliste, `r`n
            if (SubStr(A_LoopField,1,2) = gemeinde  and subStr(A_LoopField,3,2) = operat)
                {
                    zeigeliste :=  A_LoopField "|" zeigeliste
                }
; write it to GUI, including a leading pipe for deleting the current entry
        GuiControl, , Jobname , |%zeigeliste%
; choose the first value of list to avoid the display of an "empty" field
        GuiControl, Choose, Jobname, 1
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33

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

Re: Refreshing / GuiControl for Dropdownlist

Post by mikeyww » 06 Dec 2022, 09:40

I'm glad that you found a way. You have a choice of having your variable include the leading pipe, or simply specifying it in the GuiControl command. That part makes no difference. You picked the second option.

Post Reply

Return to “Ask for Help (v1)”