Jump to content

Dropdown to fill Text to imput field after choosing the dropdown.


Go to solution Solved by Nine,

Recommended Posts

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>


; Pfad zur INI-Datei
Global $sIniFile = "C:\Users\Crashrider\Desktop\BFB_Tool\Source\Standorte.ini"

; Erstellt GUI
Global $hGUI = GUICreate("INI Dropdown", 400, 200)

; Erstellt ComboBox
Global $cComboBox = GUICtrlCreateCombo("", 10, 10, 150, 25, $CBS_DROPDOWNLIST)

; Liest Abschnitte aus INI-Datei
Global $aSections = IniReadSectionNames($sIniFile)

; Überprüft, ob Abschnitte vorhanden sind
If Not @error Then
    ; Fügt Abschnitte zur ComboBox hinzu
    GUICtrlSetData($cComboBox, "|" & _ArrayToString($aSections, "|"))
    GUICtrlSetState($cComboBox, $GUI_FOCUS) ; Setzt den Fokus auf die ComboBox
EndIf

; Erstellt Textfelder
Global $cTextField1 = GUICtrlCreateInput("", 180, 10, 200, 20)
Global $cTextField2 = GUICtrlCreateInput("", 180, 40, 200, 20)
Global $cTextField3 = GUICtrlCreateInput("", 180, 70, 200, 20)
Global $cTextField4 = GUICtrlCreateInput("", 180, 100, 200, 20)
Global $cTextField5 = GUICtrlCreateInput("", 180, 130, 200, 20)

; Registriert Event für die ComboBox
GUIRegisterMsg($WM_COMMAND, "OnComboBoxChange")

GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func OnComboBoxChange($hWnd, $iMsg, $wParam, $lParam)
    If $wParam = $cComboBox And BitAND(GUIGetMsgCode(), $CBN_SELCHANGE) Then
        ; Liest ausgewählten Abschnitt aus ComboBox
        Local $sSelectedSection = GUICtrlRead($cComboBox)

        ; Überprüft, ob ein Abschnitt ausgewählt wurde
        If $sSelectedSection <> "" Then
            ; Liest Schlüssel-Wert-Paare aus ausgewähltem Abschnitt
            Local $aKeyValuePairs = IniReadSection($sIniFile, $sSelectedSection)

            ; Überprüft, ob Schlüssel-Wert-Paare vorhanden sind
            If Not @error Then
                ; Setzt die Werte in die Textfelder
                GUICtrlSetData($cTextField1, GetValueFromIniArray($aKeyValuePairs, "Var1"))
                GUICtrlSetData($cTextField2, GetValueFromIniArray($aKeyValuePairs, "Var2"))
                GUICtrlSetData($cTextField3, GetValueFromIniArray($aKeyValuePairs, "Var3"))
                GUICtrlSetData($cTextField4, GetValueFromIniArray($aKeyValuePairs, "Var4"))
                GUICtrlSetData($cTextField5, GetValueFromIniArray($aKeyValuePairs, "Var5"))
            EndIf
        EndIf
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc

Func GetValueFromIniArray($aArray, $sKey)
    For $i = 1 To $aArray[0][0]
        If $aArray[$i][0] = $sKey Then
            Return $aArray[$i][1]
        EndIf
    Next
    Return ""
EndFunc

thats the Code i gues that does not perform...
GUIRegisterMsg($WM_COMMAND, "OnComboBoxChange")

I would love to change to setonevent mode but cant find an example für setonevent for dropdown with an ini File.

Ini looks like this
 

[Ludwigshafen]
Var1=Wert1
Var2=Wert2
Var3=Wert3
Var4=Wert4
Var5=wert5

[Berlin]
Var1=Wert1
Var2=Wert2
Var3=Wert3
Var4=Wert4
Var5=wert5


Realy could use some help. Cheers
 

Link to comment
Share on other sites

  • Solution

Use this instead in WM_COMMAND as per MSDN:

If _WinAPI_LoWord($wParam) = $cComboBox And _WinAPI_HiWord($wParam) = $CBN_SELCHANGE Then

and also use this instead to get rid of count :

GUICtrlSetData($cComboBox, "|" & _ArrayToString($aSections, "|", 1))

 

Edited by Nine
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...