Problem mit Inhalt der ComboBox

  • Ich hätte da mal ne Frage ...

    Ich möchte gerne Inhalte ins dropdown einer Combobox schreiben, das funktioniert soweit auch,
    leider kann ich aber die Inhalte die schon geschrieben wurden nicht einfach löschen, und das müsste schon auch geschehen.

    Hier mal die Codezeilen (achtung, benutzt eine googlefunktion, also Internetzugriff)

    [autoit]

    #include <ComboConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <inet.au3>
    #include <array.au3>
    #include <GUIComboBox.au3>
    #include <WindowsConstants.au3>
    #include <EditConstants.au3>
    #include <StaticConstants.au3>

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

    Global $Combo1, $data, $olddata

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 515, 42, 288, 338)
    $Combo1 = GUICtrlCreateCombo("Combo1", 8, 8, 497, 25)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch

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

    If GUICtrlRead($Combo1) <> "" Then
    $data = GUICtrlRead($Combo1)
    If $olddata <> $data Then
    If StringLen($data) < 3 Then
    Else
    $suggestions = _GoogleSuggestions($data)
    _GUICtrlComboBox_BeginUpdate($Combo1)
    For $i = 1 To UBound($suggestions) - 1
    _GUICtrlComboBox_AddString($Combo1, $suggestions[$i])
    Next
    _GUICtrlComboBox_EndUpdate($Combo1)
    EndIf
    EndIf
    $olddata = $data
    EndIf
    WEnd

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

    Func _Edit_Changed()
    _GUICtrlComboBox_AutoComplete($Combo1)
    EndFunc ;==>_Edit_Changed

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

    Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
    If Not IsHWnd($Combo1) Then $hWndCombo = GUICtrlGetHandle($Combo1)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $hWndFrom
    Case $Combo1, $hWndCombo
    Switch $iCode
    Case $CBN_CLOSEUP ; Sent when the list box of a combo box has been closed
    _DebugPrint("$CBN_CLOSEUP" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $CBN_DBLCLK ; Sent when the user double-clicks a string in the list box of a combo box
    _DebugPrint("$CBN_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $CBN_DROPDOWN ; Sent when the list box of a combo box is about to be made visible
    _DebugPrint("$CBN_DROPDOWN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $CBN_EDITCHANGE ; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box
    _DebugPrint("$CBN_EDITCHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    _Edit_Changed()
    ; no return value
    Case $CBN_EDITUPDATE ; Sent when the edit control portion of a combo box is about to display altered text
    _DebugPrint("$CBN_EDITUPDATE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $CBN_ERRSPACE ; Sent when a combo box cannot allocate enough memory to meet a specific request
    _DebugPrint("$CBN_ERRSPACE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $CBN_KILLFOCUS ; Sent when a combo box loses the keyboard focus
    _DebugPrint("$CBN_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box
    _DebugPrint("$CBN_SELCHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $CBN_SELENDCANCEL ; Sent when the user selects an item, but then selects another control or closes the dialog box
    _DebugPrint("$CBN_SELENDCANCEL" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $CBN_SELENDOK ; Sent when the user selects a list item, or selects an item and then closes the list
    _DebugPrint("$CBN_SELENDOK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    Case $CBN_SETFOCUS ; Sent when a combo box receives the keyboard focus
    _DebugPrint("$CBN_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode)
    ; no return value
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_COMMAND

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

    Func _GoogleSuggestions($sSuggest); Retruns an Array of Suggestions
    Local $sSource, $aResults;, $aQueries
    $sSource = _INetGetSource("http://google.de/complete/search?output=toolbar&q=" & $sSuggest)
    If @error Then Return SetError(1)
    $aResults = StringRegExp($sSource, '<CompleteSuggestion><suggestion data="(.*?)"/>', 3)
    ;~ $sQueries = StringRegExp($source, '"/><num_queries int="(\d{0,})"/>', 3)
    Return $aResults
    EndFunc ;==>_GoogleSuggestions

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

    Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
    "!===========================================================" & @LF & _
    "+======================================================" & @LF & _
    "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
    "+======================================================" & @LF)
    EndFunc ;==>_DebugPrint

    [/autoit]

    Ich hab versucht die Box mit _GUICtrlComboBox_ResetContent zu löschen, was leider dazu führt, dass auch jeder bisher eingetippte Buchstabe sich verabschiedet (wenig sinnvoll ;))
    Ein nachträgliches setzen von _GUICtrlComboBox_SetEditText mit dem bisher eingegebenen text ($data) hilft leider auch überhauptnicht weiter.
    über eine Schleife (zeile 34ff) die einzelnen Einträge zu löschen ist auch in die Hose gegangen.
    Denn Mausbewegung in der Combobox lässt danach unvorhersehbar dinge verschwinden, was auch irgendwie nicht Sinn der Sache war ;)

    [autoit]

    For $i=0 to _GUICtrlComboBox_GetCount($Combo1)
    _GUICtrlComboBox_DeleteString($Combo1, $i)
    Next

    [/autoit]

    Nun brauch ich also doch Eure Hilfe:
    Wie kann ich, ohne die bisherige Eingabe zu verlieren die Combobox löschen und danach dennoch etwas aus Ihr wählen?
    (Also ganz wie sich google selber verhält)

    'sid

  • Du meinst wenn du was eintippst, das sich dann die Vorschläge immer aktualisieren zudem was du eingetippt hast?

  • Exakt, analog zum Vorschlagspopup von google selbst quasi.
    oder
    Exakt analog zum Vorschlagspopup von google selbst, quasi.

    Ganz wie man möchte, meinen meine ich beides ;)

    'sid

    PS Ich fürchte es wird aber eh nichts draus, weil sich die Google vorschläge nicht so anpassen lassen wie ich möchte;
    nichts desto weniger, auf die Frage hätte ich dennoch gerne eine Antwort, vielleicht brauch man's nochmal woanders

  • mit einer Combobox die über "GUICtrlCreateCombo" erzeugt wird geht folgendes:

    [autoit]

    GUICtrlSetData($combobox, "")

    [/autoit]

    evtl funktioniert das auch in deinem Fall

    Gruß

    Prajoss

    "Never touch a running System!"