DropDownList or ComboBox - best solution?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Nosyarg
Posts: 23
Joined: 16 Oct 2018, 16:23

DropDownList or ComboBox - best solution?

Post by Nosyarg » 27 Sep 2022, 16:12

I've got a combination of macros generating different portions of a CSV. MACRO1 is a form that builds the basics of data from a GUI into a CSV, output example below:

DATA1A,DATA1B,DATA1C,DATA1D,DATA1E,DATA1F,DATA1G
DATA2A,DATA2B,DATA2C,DATA2D,DATA2E,DATA2F,DATA2G
DATA3A,DATA3B,DATA3C,DATA3D,DATA3E,DATA3F,DATA3G

The B column is always blank after this first macro, as the operator does not have the information to include here.

MACRO2 reads the CSV elements into a GUI and offers a DropDownList for the B column entries. Upon submission of the MACRO2 GUI, it writes all the data back to the CSV (including the new DDL data). This CSV is parsed by a display macro and shown as a fullscreen GUI.

If a change needs to be made after MACRO2 is submitted, the operator reloads MACRO2. The problem is that MACRO2 doesn't read anything from B column, it just offers DropDownLists, where the operator has to re-enter all the selections every time.

How can I make my MACRO2 read DATA1B and pre-populate the DropDownList with this choice (since it technically is already written to the CSV? I'd be fine if it prepopulated each time, as the blank generated from MACRO1 would be a good starting spot.

Should I consider making these ComboBoxes instead of DropDownLists? Can a variable pre-fill the entry of a ComboBox, while still allowing the DropDown options?

User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: DropDownList or ComboBox - best solution?

Post by Smile_ » 27 Sep 2022, 17:15

Here are some suggestions on MACRO2:
In the auto-execute section of the script save the csv file content in variable of your choice using FileRead command.
Now get the column B data from the variable you choose to store the csv file content and populate the DropDownList, for example:
assuming you added a DropDownList control like follow Gui, Add, DropDownList, vColumnB it would be something like this:

Code: Select all

FileRead, ReadCSVFileContent, Data.csv
Loop, Parse, ReadCSVFileContent, `r, `n
{
    GuiControl,, ColumnB, % StrSplit(A_LoopField, ",")[2] (A_Index = 1 ? "||" : "")
}
Now column B should be loaded.
Also adding more data to the DDL will require you at least an input control, so when you submit it, the script should update the csv file and the DDL.
HTH

Nosyarg
Posts: 23
Joined: 16 Oct 2018, 16:23

Re: DropDownList or ComboBox - best solution?

Post by Nosyarg » 28 Sep 2022, 10:32

Thanks... since I was already parsing the CSV for the rest of the GUI, I was hoping I could just use the pre-existing data in R1C2 to pre-fill the text portion of a Combo Box, while still allowing the drop-down option to have other alternatives.

For example, if column 2 of the CSV says "CH.2", the macro would fill that value into the text portion of the ComboBox, while still allowing the other options (example, CH.1|CH.2|CH.3|CH.4, etc).

I figured having the system pre-fill the blank of a ComboBox would be easy, but I'm finding that ComboBoxes don't have the same controls as other fields, such as limits on the number of characters allowed.

I'll keep trying to make this work. I wish I could share the code directly, but I'm prohibited by my company from supplying the script/options.

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: DropDownList or ComboBox - best solution?

Post by flyingDman » 28 Sep 2022, 10:56

Maybe this example helps:

Code: Select all

fileread, csv, csvtest.csv
if (!csv or errorlevel)
	{
	csv =
	(Ltrim
	apple,,red
	orange,,orange
	lemon,,yellow
	lime,,green
	)
	}
slctn := "1|2|3|4|5|6|7|8|"
for x,y in z := strsplit(trim(csv,"`n"),"`n","`r")
	{
	gui, add, edit, 	xm 		w80 center 	vC1_%x%,	% strsplit(y,",").1
	gui, add, DDL,		x+5 	w30 		vC2_%x%, 	% strreplace(slctn, tmp:=strsplit(y,",").2, tmp "|")
	gui, add, edit, 	x+5 	w80 center 	vC3_%x%,	% strsplit(y,",").3
	}
gui, add, button, y+10 x+-25,OK
gui, show
return

buttonOK:
gui, submit
lst := ""
loop, % z.count()
	lst .= (a_index = 1 ? "" : "`n") . C1_%a_index% "," C2_%a_index% "," C3_%a_index%
filedelete, csvtest.csv
fileappend, % lst, csvtest.csv
reload
exitapp
The crucial part is line 16 where the existing value is replaced by that same value followed by a | to indicate that that element will be selected by default
14.3 & 1.3.7

Post Reply

Return to “Ask for Help (v1)”