Combobox: Angezeigter Wert vs. Tatsächlicher Wert

  • Hallo gleich nochmal,

    hab noch ne Frage:
    Bei HTML kann man in einer Selectbox (was ja die Combobox der HTML-Welt ist) zwei Angaben machen:
    1. der Wert, der in der Combobox angezeigt werden soll
    2. der Wert, der nach dem Auswählen eines Eintrags im Hintergrund gültig ist.

    Beispiel:
    <select box name="Kunden_id">
    <option value="1">Max Meier</option>
    <option value="2">Michael Meier</option>
    </select>

    Hintergrund: Ich will, dass in meiner SQL Datenbank nicht Max Meier abgespeichert wird, sondern die entsprechende ID, die im HTML-Beispiel als "value" abgelegt ist.

    Geht sowas mit Autoit-Mitteln?

    Viele Grüße

    Daniel

  • Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <ComboConstants.au3>
    #include <GuiComboBoxEx.au3>
    #region - GUI Create
    GUICreate('', 200, 100)
    $Combo1 = GUICtrlCreateCombo("bla", 8, 8, 100, Default, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, "blub|blubber")
    $Button = GUICtrlCreateButton("klick", 8, 35)
    GUISetState()
    #endregion - GUI Create

    [/autoit] [autoit][/autoit] [autoit]

    #region - GUI SelectLoop
    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
    Exit
    Case $msg = $Button
    $index = _GUICtrlComboBoxEx_GetCurSel(GUICtrlGetHandle($Combo1))
    MsgBox(0, 0, $index)
    EndSelect
    WEnd
    #endregion - GUI SelectLoop

    [/autoit]
  • Hallo basementmedia,

    da die ComboBox, ja abhängig von einem DB-Query gefüllt wird ist der Index (je nach Query) unterschiedlich und daher untauglich. Du solltest dafür

    [autoit]

    _GUICtrlComboBoxEx_SetItemParam
    _GUICtrlComboBoxEx_GetItemParam

    [/autoit]

    verwenden,

    mfg autoBert

  • Hi autoBert,

    _GUICtrlComboBoxEx_SetItemParam

    kuck ich mir auf jeden Fall gleich mal an.
    Könnte evtl. das sein, was ich such...

    Vielen Dank und viele Grüße

    Daniel

  • Hallo basementmedia,

    ich habe einmal ein kleines Beispiel gemacht:

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <GuiComboBoxEx.au3>
    #include <GuiImageList.au3>
    #include <GuiConstantsEx.au3>
    #include <File.au3>
    #include <Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    $Debug_CB = False ; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work

    [/autoit] [autoit][/autoit] [autoit]

    Global $hCombo

    [/autoit] [autoit][/autoit] [autoit]

    _Main()

    [/autoit] [autoit][/autoit] [autoit]

    Func _Main()
    Local $hGUI, $Button
    Dim $aFile[1], $aItem, $nMsg
    _FileReadToArray(@ScriptDir & "\Querverweis.txt", $aFile)
    Dim $aCombo[$aFile[0]][2]
    For $i = 1 To $aFile[0]
    $aItem = StringSplit($aFile[$i], "|", 2)
    $aCombo[$i - 1][0] = $aItem[0]
    $aCombo[$i - 1][1] = $aItem[1]
    Next
    _ArrayDisplay($aCombo, "2DArray wie auch von _SQLite_GetTable2d zurückgegeben")
    ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Get Item Param", 400, 300)
    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, 100)
    _GUICtrlComboBoxEx_BeginUpdate($hCombo)
    For $i = 1 To UBound($aCombo) - 1
    _GUICtrlComboBoxEx_AddString($hCombo, $aCombo[$i][1],-1,-1,-1,-1,$aCombo[$i][0])
    Next
    _GUICtrlComboBoxEx_EndUpdate($hCombo)
    $Button = GUICtrlCreateButton("Abfrage",2,120)
    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    case $Button
    $i = _GUICtrlComboBoxEx_GetCurSel($hCombo)
    $aItem = _GUICtrlComboBoxEx_GetItem($hCombo,$i)
    ConsoleWrite("Anwendungsspezifischer Wert für " & $aItem[0] & " = " & $aItem[6] &@CRLF)
    EndSwitch
    WEnd
    EndFunc ;==>_Main

    [/autoit] [autoit][/autoit] [autoit]

    ;#cs
    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hCombo
    Switch $iCode
    Case $CBEN_GETDISPINFOW ; Sent to retrieve display information about a callback item
    Local $tInfo = DllStructCreate($tagNMCOMBOBOXEX, $ilParam)
    Local $aItem = _GUICtrlComboBoxEx_GetItem ($hCombo, DllStructGetData($tInfo, "Item"))
    ConsoleWrite("Anwendungsspezifischer Wert für " & $aItem[0] & " = " & $aItem[6] &@CRLF)
    ;Return 0
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY
    ;#ce

    [/autoit]

    für das Beispiel wird noch Der Inhalt kann nicht angezeigt werden, da er nicht mehr verfügbar ist. benötigt,

    mfg autoBert

  • Hi autoBert,

    vielen Dank für deine Hilfe! Ist echt super nett, dass du dir die Mühe machst.

    funktioniert wunderbar, d.h. du wirst in den Credits erwähnt ;)

    Viele Grüße

    Daniel