DDL: can't flush DDL2 values when changing DDL1 choice Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
KRG-23
Posts: 19
Joined: 07 Jun 2016, 05:45
Location: France

DDL: can't flush DDL2 values when changing DDL1 choice

05 Nov 2018, 09:06

Hey all,

I'm trying to create DDLs from a .INI file. I managed to eventually do it but I can't change DDL2 content when changing choice in DDL1... the script keeps adding the content instead of replacing it.

The idea :
DDL1 > choice1 creates DDL2 with choices2.1
DDL1 > choice2 creates DDL2 with choices2.2
DDL1 > choice3 creates DDL2 with choices2.3

I've tried this trick:
Setup the DropDownList with a hwnd as follows:

Code: Select all

Gui, Add, DropDownList, hwndDDL_ID, Item1|Item2|Item3
Then to clear it use:

Code: Select all

SendMessage, 0x014E, -1, 0,, ahk_id %DDL_ID%
But it's not working ...

Thank you for your help!

Here's the script:

Code: Select all

#NoEnv
#singleinstance force
;==================================================
;VARIABLES
;==================================================
List_DDL := "Choose:||"

; ==================================================
; GUI
; ==================================================

Gosub Show_Categories
Gui, Color, cFFFFFF,
Gui, Add, MonthCal, 28 x12 vSTR_Date, 
Gui, Add, DropDownList, x12 y+10 w200 gShow_Subcategories vCategories_DDL, % List_DDL . Category_Name 
Gui, Add, DropDownList, x12 y+10 w200 gShow_Tasks vSubcategories_DDL,
Gui, Add, Edit, x12 y+10 Section w110 hp vHours, Hours
Gui, Add, Edit, x132 ys w110 hp vMinutes, Minutes
Gui, Show, AutoSize, STR
Return

; ==================================================
; LABELS
; ==================================================

Show_Categories:
FileRead, STR_Codes_Content, %A_ScriptDir%\str_codes.ini
Loop Parse, STR_Codes_Content, [
	{
	IfInString, A_LoopField, ]
		{
		Count+=1
		StringGetPos, Cat, A_LoopField, ]
		StringLeft, Temp, A_LoopField, %Cat%
		Category_Name.=Temp . "|"
		}
	}
StringTrimRight, Category_Name, Category_Name, 7 ; removes Tasks and last |
Return

Show_Subcategories: 
Gui, Submit, NoHide
IniRead, STR_Subcategories, %A_ScriptDir%\str_codes.ini, %Categories_DDL%
StringSplit, Sub_Cat, STR_Subcategories, `n
Loop, % Sub_Cat0
{
	Subcategory_Name := Subcategory_Name Sub_Cat%A_Index% "|"
}
StringTrimRight, Subcategory_Name, Subcategory_Name, 1 ; removes last |
GuiControl,,Subcategories_DDL, % List_DDL . Subcategory_Name
Return


GuiClose:
ExitApp

Show_Tasks:
Write_File:
Return
The INI file:

Code: Select all

[Common & Internal]
Change Mgmt=OT0305
Pulse Meetings=C52793
Education=C52795
Workshops=C52833
Skill Transfer=C54438
[Infrastructure]
Windows servers=OT0087
Database SQL Server=OT0121
[Services & Projects]
SFR misc=AG1677
i80=UL0230
[TASKS]
OT0305=Ope
C52793=Other
C52795=Educ
C52833=Imp
C54438=Comp
OT0087=1.0 Gen
OT0121=1.11 Service Dev
OT0121=1.2 Service maint
OT0121=1.3 Service Prob
OT0121=1.4 Service Own
OT0121=1.5 Service Deliver
aifritz
Posts: 108
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: DDL: can't flush DDL2 values when changing DDL1 choice

05 Nov 2018, 11:46

Can't you use the GuiControl command?

Example look here: https://autohotkey.com/boards/viewtopi ... efresh+gui

DDL - > DropDownList
awel20
Posts: 141
Joined: 19 Mar 2018, 14:09

Re: DDL: can't flush DDL2 values when changing DDL1 choice

05 Nov 2018, 11:53

Code: Select all

Gui, Add, DropDownList, hwndDDL_ID, Item1|Item2|Item3
Gui, Show
MsgBox
; https://autohotkey.com/docs/commands/GuiControl.htm - "To replace (overwrite) the list instead, include a pipe as the 
; first character (e.g. |Red|Green|Blue)."
GuiControl,, % DDL_ID, |Item4|Item5|Item6
wolf_II
Posts: 2679
Joined: 08 Feb 2015, 20:55

Re: DDL: can't flush DDL2 values when changing DDL1 choice  Topic is solved

05 Nov 2018, 11:54

There are two issues here:
1 - you have to empty Subcategory_Name before entering the Loop.
2 - you have to use a leading pipe symbol to overwrite, otherwise it will append.

Code: Select all

Show_Subcategories:
    Gui, Submit, NoHide
    IniRead, STR_Subcategories, %A_ScriptDir%\str_codes.ini, %Categories_DDL%
    StringSplit, Sub_Cat, STR_Subcategories, `n
    Subcategory_Name := ""                                                      ; <<<<< here <<<
    Loop, % Sub_Cat0
        Subcategory_Name := Subcategory_Name Sub_Cat%A_Index% "|"
    StringTrimRight, Subcategory_Name, Subcategory_Name, 1 ; removes last |
    GuiControl,,Subcategories_DDL, % "|" List_DDL . Subcategory_Name            ; <<<<< here <<<
Return
I hope this helps.
Ahk_fan
Posts: 50
Joined: 31 Aug 2018, 14:34

Re: DDL: can't flush DDL2 values when changing DDL1 choice

05 Nov 2018, 15:19

HI,

here ist a solution:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

gui, add, DropDownList, vmyfirstDDL gChangeDDL1, Item1|Item2|Item3			;create first DDL
gui, add, DropDownList, vmysecondDDL,										;create second DDL
gui, add, Button, gNewLoad													; only for test
gui, show
return

GuiClose:
ExitApp

NewLoad:
reload
return

ChangeDDL1:
gui, submit, nohide															; take choosen Vars from parent Gui
GuiControl, , mysecondDDL, |            									; clear DDL2
IniRead, VarMySecondDDL, %A_ScriptDir%\myini.ini, konfig, %myfirstDDL%		; load Vars from INI with selected ITEM from DDL1
GuiControl, , mysecondDDL, %VarMySecondDDL%									; fill DDL2 with Items from INI
return
and here text of an INI-File (myini.ini)
[konfig]
Item1=a1|b2|c3
Item2=d4|e5|f6
Item3=g7|h8|i9
regards,
AHK_fan :)
User avatar
KRG-23
Posts: 19
Joined: 07 Jun 2016, 05:45
Location: France

Re: DDL: can't flush DDL2 values when changing DDL1 choice

06 Nov 2018, 04:45

@awel20 & @wolf_II: thank you both, I misunderstood this line in the documentation for this GuiControl ...
@Ahk_fan: thanks for your example, now my issue is fixed :)

Return to “Ask For Help”

Who is online

Users browsing this forum: andrewvanmarle, Gdark, Google [Bot], imjuniu and 140 guests