Combobox Input ändern

  • Hi,
    wie kann ich den Text einer Combobox mithilfe einer Inputbox und einem Button ändern, ohne einen neuen Eintrag zu erstellen?


    Ich habe es so probiert:

    Spoiler anzeigen
    [autoit]

    #include
    #include
    #include
    #include
    #include
    #Region ### START Koda GUI section ### Form=
    $Form = GUICreate("Test", 162, 69, 327, 241)
    GUISetBkColor(0xFFFFFF)
    $Combo1 = GUICtrlCreateCombo("Test 1", 8, 8, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    GUICtrlSetData(-1, "Test 2|Test 3")
    $Input1 = GUICtrlCreateInput("Text", 8, 40, 97, 21)
    $Button1 = GUICtrlCreateButton("Save", 108, 36, 43, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    GUICtrlSetData($Combo1, $Input1)
    EndSwitch
    WEnd

    [/autoit]


    Bei diesem Script wird aber ein neuen Eintrag erstellt und der Text ist nicht der Text der Inputbox , sondern 4

    4 Mal editiert, zuletzt von Slyfex (27. November 2009 um 23:20)

  • Das ist ja nicht das Problem. Allerdings wolltest du eben
    1. einen Wert aus der ComboBox auswählen
    2. einen neuen Wert in die Combobox eintragen
    3. den alten wert dadurch überschreiben UND das für den nächsten "start" übernehmen

    das ist wie gesagt nicht so einfach, oder ich komm einfach nicht drauf..

    zu deinem jetzigen problem

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <ComboConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GUIComboBox.au3>
    #Region ### START Koda GUI section ### Form=
    $Form = GUICreate("Test", 162, 69, 327, 241)
    GUISetBkColor(0xFFFFFF)
    $Combo1 = GUICtrlCreateCombo("Test 1", 8, 8, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    GUICtrlSetData(-1, "Test 2|Test 3")
    $Input1 = GUICtrlCreateInput("Text", 8, 40, 97, 21)
    $Button1 = GUICtrlCreateButton("Save", 108, 36, 43, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    ;~ _GUICtrlComboBox_ReplaceEditSel(ControlGetHandle($Form,"",$Combo1),GUICtrlRead($Combo1))
    $sel = _GUICtrlComboBox_GetCurSel(ControlGetHandle($Form,"",$Combo1))
    _GUICtrlComboBox_InsertString(ControlGetHandle($Form,"",$Combo1),GUICtrlRead($Input1),_GUICtrlComboBox_GetCurSel(ControlGetHandle($Form,"",$Combo1)))
    _GUICtrlComboBox_DeleteString(ControlGetHandle($Form,"",$Combo1),_GUICtrlComboBox_GetCurSel(ControlGetHandle($Form,"",$Combo1)))
    _GUICtrlComboBox_SetCurSel(ControlGetHandle($Form,"",$Combo1),$sel)
    EndSwitch
    WEnd

    [/autoit]
    • Offizieller Beitrag

    Wenn ich das richtig verstanden habe suchst du sowas:

    Spoiler anzeigen
    [autoit]

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

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

    #Region ### START Koda GUI section ### Form=
    $Form = GUICreate("Test", 162, 69, 327, 241)
    GUISetBkColor(0xFFFFFF)
    $Combo1 = GUICtrlCreateCombo("Test 1", 8, 8, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    GUICtrlSetData(-1, "Test 2|Test 3")
    $Input1 = GUICtrlCreateInput("Text", 8, 40, 97, 21)
    $Button1 = GUICtrlCreateButton("Save", 108, 36, 43, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    $Sel = _GUICtrlComboBox_GetCurSel($Combo1)
    _GUICtrlComboBox_DeleteString($Combo1, $Sel)
    _GUICtrlComboBox_InsertString($Combo1,GUICtrlRead( $Input1), $Sel)
    _GUICtrlComboBox_SetCurSel($Combo1, $Sel)
    ;~ GUICtrlSetData($Combo1,GUICtrlRead( $Input1))

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

    EndSwitch
    WEnd

    [/autoit]
  • Danke, beides funktioniert.
    Jetzt müsste ich das ganze noch in eine .ini schreiben können, um den Namen dauerhaft speichern zu können
    Z.B. mit so einer Form

    Spoiler anzeigen
    [autoit]

    #Region ### START Koda GUI section ### Form=
    $Form = GUICreate("Test", 162, 69, 327, 241)
    GUISetBkColor(0xFFFFFF)
    $Combo1 = GUICtrlCreateCombo(IniRead("Namen.ini", "Namen", "1", @ScriptDir), 8, 8, 145, 25)
    GUICtrlSetData(-1, IniRead("Namen.ini", "Namen", "2", @ScriptDir)&"|"&IniRead("Namen.ini", "Namen", "3", @ScriptDir))
    $Input1 = GUICtrlCreateInput("Text", 8, 40, 97, 21)
    $Button1 = GUICtrlCreateButton("Save", 108, 36, 43, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit]
  • Spoiler anzeigen
    [autoit]

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

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

    #Region ### START Koda GUI section ### Form=
    $Form = GUICreate("Test", 162, 69, 327, 241)
    GUISetBkColor(0xFFFFFF)
    $aIniSection = IniReadSection("test.ini","Combo")
    $Combo1 = GUICtrlCreateCombo($aIniSection[1][1], 8, 8, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    For $i = 2 to $aIniSection[0][0]
    GUICtrlSetData($Combo1,$aIniSection[$i][1],"")
    Next
    $Input1 = GUICtrlCreateInput("Text", 8, 40, 97, 21)
    $Button1 = GUICtrlCreateButton("Save", 108, 36, 43, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    $Sel = _GUICtrlComboBox_GetCurSel($Combo1)
    _GUICtrlComboBox_DeleteString($Combo1, $Sel)
    _GUICtrlComboBox_InsertString($Combo1,GUICtrlRead( $Input1), $Sel)
    _GUICtrlComboBox_SetCurSel($Combo1, $Sel)
    ;~ GUICtrlSetData($Combo1,GUICtrlRead( $Input1))
    $aComboList = _GUICtrlComboBox_GetListArray($Combo1)
    For $i = 1 to $aComboList[0]
    IniWrite("test.ini","Combo",$i-1,$aComboList[$i])
    Next
    EndSwitch
    WEnd

    [/autoit]

    und die .ini sieht dann so aus:

    Spoiler anzeigen

    [Combo]
    0=Hallo
    1=Ich bin 2
    2=Mir is langweilig

    • Offizieller Beitrag

    2. Möglichkeit:

    Spoiler anzeigen
    [autoit]

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

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

    #Region ### START Koda GUI section ### Form=
    $Form = GUICreate("Test", 162, 69, 327, 241)
    GUISetBkColor(0xFFFFFF)
    $Combo1 = GUICtrlCreateCombo("", 8, 8, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
    $Input1 = GUICtrlCreateInput("Text", 8, 40, 97, 21)
    $Button1 = GUICtrlCreateButton("Save", 108, 36, 43, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $temp = IniRead(@ScriptDir & "\Test.ini", "Settings", "Combo", "Test 1|Test 2|Test 3")
    $aTmp = StringSplit($temp, "|")
    For $i = 1 To $aTmp[0]
    _GUICtrlComboBox_InsertString($Combo1, $aTmp[$i])
    Next
    _GUICtrlComboBox_SetCurSel($Combo1, 0)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    $Sel = _GUICtrlComboBox_GetCurSel($Combo1)
    _GUICtrlComboBox_DeleteString($Combo1, $Sel)
    _GUICtrlComboBox_InsertString($Combo1, GUICtrlRead($Input1), $Sel)
    _GUICtrlComboBox_SetCurSel($Combo1, $Sel)
    $tempA = _GUICtrlComboBox_GetListArray($Combo1)
    _ArrayDelete($tempA, 0)
    $sTemp = _ArrayToString($tempA)
    IniWrite(@ScriptDir & "\Test.ini", "Settings", "Combo", $sTemp)
    EndSwitch

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

    WEnd

    [/autoit]
  • Das von SEuBo funktioniert perfekt, sieht aber kompliziert aus (kann man das vereinfachen)
    Das Script von dir funktioniert zwar auch, fügt aber immer ein neues Input ein

  • Guten Hunger :)
    Danke für dein Angebot, aber wenn man alles andere machen lässt, lernt man nichts dabei, deswegen werd ichs mir jetzt mal genauer anschauen

    • Offizieller Beitrag
    Zitat

    Das Script von dir funktioniert zwar auch, fügt aber immer ein neues Input ein

    Wo? Verstehe das nicht, es wird nix eingefügt. Erklär mal genauer. SEuBo´s Script braucht auch umbeding die INI. Meins funtz auch ohne zuvor erstellte INI. :thumbup:

    Edit hab´s noch ein bischen erweitert.

    Spoiler anzeigen
    [autoit]

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

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

    #Region ### START Koda GUI section ### Form=
    $Form = GUICreate("Test", 162, 69, 327, 241)
    GUISetBkColor(0xFFFFFF)
    $Combo1 = GUICtrlCreateCombo("", 8, 8, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
    $Input1 = GUICtrlCreateInput("Text", 8, 40, 97, 21)
    $Button1 = GUICtrlCreateButton("Save", 108, 36, 43, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $aTmp = StringSplit(IniRead(@ScriptDir & "\Test.ini", "Settings", "Combo", "Test 1|Test 2|Test 3"), "|")
    For $i = 1 To $aTmp[0]
    _GUICtrlComboBox_InsertString($Combo1, $aTmp[$i])
    Next
    _GUICtrlComboBox_SetCurSel($Combo1, 0)
    GUICtrlSetData($Input1,GUICtrlRead($Combo1))
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Combo1
    GUICtrlSetData($Input1,GUICtrlRead($Combo1))
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    $Sel = _GUICtrlComboBox_GetCurSel($Combo1)
    _GUICtrlComboBox_DeleteString($Combo1, $Sel)
    _GUICtrlComboBox_InsertString($Combo1, GUICtrlRead($Input1), $Sel)
    _GUICtrlComboBox_SetCurSel($Combo1, $Sel)
    $tempA = _GUICtrlComboBox_GetListArray($Combo1)
    $sTemp = _ArrayToString($tempA,"|",1)
    IniWrite(@ScriptDir & "\Test.ini", "Settings", "Combo", $sTemp)
    EndSwitch
    WEnd

    [/autoit]
  • Kann man das verhindern?

    [autoit]

    $Combo1 = GUICtrlCreateCombo($aIniSection[1][1], 8, 8, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$CBS_DROPDOWNLIST))

    [/autoit]


    $CBS_DROPDOWNLIST - dann kann man nix mehr löschen ;D
    Simpel, aber es funktioniert.
    Das Problem ist einfach, dass _GUICtrlComboBox_GetCurSel() -1 ausgibt, sobald der Wert geändert wurde (weil es ja keine "auswahl" in der ComboBox mehr ist). Das war auch das Problem an dem ich zu Anfang zu knabbern hatte, als du alles noch nur über eine ComboBox laufen lassen wolltest.

    Zitat von Raupi

    Meins funtz auch ohne zuvor erstellte INI


    ;(
    Könnt meins ja auch so weit umbauen, dass die Ini nicht zwingend gebraucht wird, aber ehrlich gesagt hatte ich da nicht so ne große Lust drauf ^^ Wenn ich alles perfektioniere, komm ich ja zu garnix mehr

    • Offizieller Beitrag

    Ach das meinst du. Da haben aber unser beiden Scripte Probleme mit. Schau dir mal die INI von SEuBo´s Script an. Der einzige Unterschied dabei ist das Schlüssel mir GuiCtrlSetData nicht doppelt beim lesen eingefügt werden.

    Spoiler anzeigen
    [autoit]

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

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

    #Region ### START Koda GUI section ### Form=
    $Form = GUICreate("Test", 162, 69, 327, 241)
    GUISetBkColor(0xFFFFFF)
    $Combo1 = GUICtrlCreateCombo("", 8, 8, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL,$CBS_DROPDOWNLIST))
    $Input1 = GUICtrlCreateInput("Text", 8, 40, 97, 21)
    $Button1 = GUICtrlCreateButton("Save", 108, 36, 43, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $aTmp = StringSplit(IniRead(@ScriptDir & "\Test.ini", "Settings", "Combo", "Test 1|Test 2|Test 3"), "|")
    For $i = 1 To $aTmp[0]
    GUICtrlSetData($Combo1,$aTmp[$i],"")

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

    Next
    _GUICtrlComboBox_SetCurSel($Combo1, 0)
    GUICtrlSetData($Input1,GUICtrlRead($Combo1))
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Combo1
    GUICtrlSetData($Input1,GUICtrlRead($Combo1))
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    $Sel = _GUICtrlComboBox_GetCurSel($Combo1)
    _GUICtrlComboBox_DeleteString($Combo1, $Sel)
    _GUICtrlComboBox_InsertString($Combo1, GUICtrlRead($Input1), $Sel)
    _GUICtrlComboBox_SetCurSel($Combo1, $Sel)
    $tempA = _GUICtrlComboBox_GetListArray($Combo1)
    $sTemp = _ArrayToString($tempA,"|",1)
    IniWrite(@ScriptDir & "\Test.ini", "Settings", "Combo", $sTemp)
    EndSwitch
    WEnd

    [/autoit]
    • Offizieller Beitrag
    Zitat

    ;(
    Könnt meins ja auch so weit umbauen, dass die Ini nicht zwingend gebraucht wird, aber ehrlich gesagt hatte ich da nicht so ne große Lust drauf ^^ Wenn ich alles perfektioniere, komm ich ja zu garnix mehr


    Sollte kein Vorwurf sein. ;) Wenn die INI nicht existiert, kackt dein Script nur leider ab.
    Aber Slyfex will ja auch was an den Script machen. :rolleyes: Hoffe ich zumindest. :thumbup:

    • Offizieller Beitrag

    Ist zwar eigentlich schon gelöst, aber hier mal meine Variante:

    Spoiler anzeigen
    [autoit]


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

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

    #Region ### START Koda GUI section ### Form=
    $Form = GUICreate("Test", 162, 69, 327, 241)
    GUISetBkColor(0xFFFFFF)
    $Combo1 = GUICtrlCreateCombo("", 8, 8, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
    $Button1 = GUICtrlCreateButton("Save", 108, 36, 43, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $sTmp = IniRead(@ScriptDir & "\Test.ini", "Settings", "Combo", "Test 1|Test 2|Test 3")
    $edit = StringMid($sTmp, StringInStr($sTmp, "|", 0, -1) + 1)
    GUICtrlSetData($Combo1, $sTmp, $edit)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Combo1
    $edit = GUICtrlRead($Combo1)
    ;~ ToolTip(GUICtrlRead($Combo1))
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    $new = GUICtrlRead($Combo1)
    If $new = "" Then
    GUICtrlSetData($Combo1, $edit)
    Else
    $sTmp = StringReplace($sTmp, $edit, $new)
    GUICtrlSetData($Combo1, "")
    GUICtrlSetData($Combo1, $sTmp, $new)
    IniWrite(@ScriptDir & "\Test.ini", "Settings", "Combo", $sTmp)
    EndIf
    EndSwitch
    WEnd

    [/autoit]


    Da kann man direkt in der Combobox den Eintrag ändern und speichern.

    • Offizieller Beitrag

    Sehr schön Oscar :thumbup:
    Ich sollte mich mal mehr mit den Bordmitteln von Autoit beschäftigen. Aus Faulheit greife ich immer
    zu den UDF-Funktionen. Dein Script ist das beste Beispiel, das man solche Sachen, auch ohne die
    UDF-Funktionen hinbekommt. Voralledingen hab ich was zu den String Funktionen gelernt. Die sind
    die ganze Zeit bei mir zu kurz gekommen. :cursing: