Display New Item in Drop Down List

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dunnerca
Posts: 13
Joined: 15 Oct 2020, 10:55

Display New Item in Drop Down List

Post by dunnerca » 23 Jan 2022, 12:12

I have a Gui which contains a drop-down list populated from reading a textfile of client names.

Code: Select all

Gui, 1:Add, DropDownList, x120 y230 w300 vClient gDDLChoice, %ClientList%
This works fine. One of the items on the DDL is "Add new client" which triggers "DDLChoice" and opens a new Gui with a text box to add the new client's name. I've put the code below. After clicking the button on Gui 2, the script will append the new client name to the end of the text file (F1). Then I have AddNewClient re-read the text file into the ClientList array, sort it, and re-open the Gui 1: (which contains the DDL of client names).

My problem is that I can't figure out how to have the ClientList updated in the DDL when Gui 1: is re-shown.

Code: Select all

DDLChoice:
	Gui, 1:Submit
	if (Client="Add new client"){
		Gui, 2:Add, Text,,Client Name:
		Gui, 2:Add, Edit, w200 vNewClient
		Gui, 2:Add, Button,gAddNewClient,Add
		Gui, 2:Show, w300 h300
	}
	else
		Gui, 1:Show
	Return
	
AddNewClient:
	Gui, 2:Submit
	FileAppend, %NewClient%`r`n,%F1%

	Loop, Read, %F1%
		ClientList .= A_LoopReadLine "|"
	Sort, ClientList
	Gui, 1:show
	Return
Any help would be most appreciated. I've scoured the forum with no result that will let me do this.

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

Re: Display New Item in Drop Down List

Post by mikeyww » 23 Jan 2022, 12:26

GuiControl may work.

dunnerca
Posts: 13
Joined: 15 Oct 2020, 10:55

Re: Display New Item in Drop Down List

Post by dunnerca » 23 Jan 2022, 12:33

Thanks for the tip. I've tried GuiControl but there doesn't seem to be an option to "redraw" the DDL. I thought of deleting the DDL and re-adding it but the "delete" option isn't available. Perhaps there's some way of updating the DDL through GuiControl that I haven't picked up on?

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

Re: Display New Item in Drop Down List

Post by mikeyww » 23 Jan 2022, 13:07

Code: Select all

str1 = Black|White|Red|Green|Blue
str2 = Orange|Black|White|Red|Green|Blue
Gui, Font, s10
Gui, Add, DropDownList, w250 vsel, %str1%
Gui, Show,, Test
F3::
GuiControl,, sel, |%str2%
MsgBox, 64, Status, Updated!
Return

dunnerca
Posts: 13
Joined: 15 Oct 2020, 10:55

Re: Display New Item in Drop Down List

Post by dunnerca » 23 Jan 2022, 13:27

mikeyww wrote:
23 Jan 2022, 13:07

Code: Select all

str1 = Black|White|Red|Green|Blue
str2 = Orange|Black|White|Red|Green|Blue
Gui, Font, s10
Gui, Add, DropDownList, w250 vsel, %str1%
Gui, Show,, Test
F3::
GuiControl,, sel, |%str2%
MsgBox, 64, Status, Updated!
Return
Thanks for your reply, again. My script is using a g-label where the new client is added. Your example doesn't use this so I'm assuming that the problem is that my new list is being created within my "AddNewClient" subroutine area?

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

Re: Display New Item in Drop Down List

Post by mikeyww » 23 Jan 2022, 13:43

Add a GuiControl command to your script. Post a revision if it does not work. The GuiControl command modifies the DDL. To learn about it, click the command in the posted script. You could also test the script that I posted, to see if that script works. You can report here about whether it does work. Here is another example of GuiControl. viewtopic.php?p=440597#p440597

dunnerca
Posts: 13
Joined: 15 Oct 2020, 10:55

Re: Display New Item in Drop Down List

Post by dunnerca » 23 Jan 2022, 13:57

mikeyww wrote:
23 Jan 2022, 13:43
Add a GuiControl command to your script. Post a revision if it does not work. The GuiControl command modifies the DDL. To learn about it, click the command in the posted script.

Code: Select all

AddNewClient:
	Gui, 2:Submit
	FileAppend, %NewClient%`r`n,%F1%

	Loop, Read, %F1%
		ClientList .= A_LoopReadLine "|"
	Sort, ClientList
	GuiControl,,1:Client, |%ClientList%
	Gui, 1:show
	Return
This code above is what I changed from the original post, using the GuiControl command you suggested. I have verified that the new client name is added to the text file (F1). Thanks for your persistence, @mikeyww .

Post Reply

Return to “Ask for Help (v1)”