Combobox Auswahl zum Ansprechen einer ListBox

  • Hallo Gemeinde,

    ich habe da ein kleines Problem, dass ich schon gelöst habe, aber mir persönlich gefällt die Lösung nicht ganz, deshalb wollte ich eure Meinung zu dem Script erfragen!

    Hier ist das Script:

    Spoiler anzeigen
    [autoit]

    #include <file.au3>
    #include <GUIConstants.au3>
    #Include <GuiComboBox.au3>
    #include <GuiConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <ListboxConstants.au3>
    #include <GUIListBox.au3>
    #Include <GuiButton.au3>
    #Include <Array.au3>

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

    Global $msg, $var

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

    $hGUI = GUICreate("", 250, 250)

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

    $hCombobox = _GUICtrlComboBox_Create($hGUI,"",10,10,100,120,$CBS_DROPDOWNLIST)
    $eButton = GUICtrlCreateButton("Enter", 140, 8, 75, 25, $BS_FLAT)
    $hList = GUICtrlCreateList("", 10, 50, 230, 190, $WS_VSCROLL + $LBS_SORT)

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

    ; GUICtrlSetOnEvent($eButton,"Enter")
    GUISetOnEvent($GUI_EVENT_CLOSE, "End")

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

    Opt("GUIOnEventMode", 1)
    GUISetState(@SW_SHOW)

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

    Dim $aRecords
    If Not _FileReadToArray("liste.txt",$aRecords) Then
    MsgBox(4096,"Error", " Error reading log to Array error:" & @error)
    Exit
    EndIf

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

    Dim $ttsystems
    If Not _FileReadToArray("ttsystem.txt",$ttsystems) Then
    MsgBox(4096,"Error", " Error reading log to Array error:" & @error)
    Exit
    EndIf

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

    Dim $maps
    If Not _FileReadToArray("liste2.txt",$maps) Then
    MsgBox(4096,"Error", " Error reading log to Array error:" & @error)
    Exit
    EndIf

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

    Dim $meta
    If Not _FileReadToArray("meta.txt",$meta) Then
    MsgBox(4096,"Error", " Error reading log to Array error:" & @error)
    Exit
    EndIf

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

    For $x = 1 to $aRecords[0]
    _GUICtrlComboBox_AddString($hCombobox,$aRecords[$x])
    Next

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

    While 1
    If _GUICtrlComboBox_GetCurSel($hCombobox) = 0 Then
    _GUICtrlListBox_ResetContent($hList)
    For $x = 1 to $maps[0]
    _GUICtrlListBox_AddString($hList,$maps[$x])
    Next
    _GUICtrlComboBox_SetCurSel($hCombobox, -1)
    EndIf
    If _GUICtrlComboBox_GetCurSel($hCombobox) = 1 Then
    _GUICtrlListBox_ResetContent($hList)
    For $x = 1 to $ttsystems[0]
    _GUICtrlListBox_AddString($hList,$ttsystems[$x])
    Next
    _GUICtrlComboBox_SetCurSel($hCombobox, -1)
    EndIf
    sleep(1000)
    WEnd

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

    Func End()
    Exit
    EndFunc

    [/autoit]

    Folgendes möchte ich erreichen:
    Ich habe eine ComboBox drin, die ihre Strings aus einer txt- Datei ausliest! Wenn ich eine Auswahl treffe soll in Echtzeit, eine Liste erzeugt werden in der Listbox, die auch aus eine txt- Datei ausgelesen wird! Je nachdem welche Auswahl man trifft, wird eine andere Liste angezeigt! Das Problem liegt bei der Auswahl; Wenn ich was auswähle, soll die Liste sofort erzeugt werden, ohne dass ich einen Button extra dafür benutze (Button ist trotzdem eingetragen aus Testzwecken)! Mit diesem Script geht das, aber es ist nicht sonderlich gut; Gibt es vielleicht eine andere Lösung oder vielleicht eine Funktion, die ich übersehen hab?

    Einmal editiert, zuletzt von egezgin (9. Juni 2009 um 14:52)

    • Offizieller Beitrag

    Kannst du mal die Textdateien anhängen damit man was zum arbeiten hat . Was mir aufgefallen ist in Zeile 20:

    [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit]


    Solltest du vor der GuiDeklaration einfügen in Zeile 12. Ausserdem benutze besser GuiCtrlCreateCombo anstatt _GUICtrlComboBox_Create dann kannst du der Combobox auch einen Event zuordnen .

  • Hab die txt- Dateien angehängt! Die Opt("GUIOnEventMode", 1) hab ich in Zeile 23, vielleicht zu spät?

    Edit: Script getestet, die Combo wird nicht mehr richtig angezeigt!

    Edit: Dateianhänge wieder entfernt!

    Einmal editiert, zuletzt von egezgin (9. Juni 2009 um 14:52)

    • Offizieller Beitrag

    Ups, hab einen Fehler im Script , probier mal das .

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <ComboConstants.au3>
    #include <file.au3>
    #include <GUIConstants.au3>
    #include <GuiComboBox.au3>
    #include <GuiConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <ListboxConstants.au3>
    #include <GUIListBox.au3>
    #include <GuiButton.au3>
    #include <Array.au3>

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

    Global $msg, $var
    Opt("GUIOnEventMode", 1)
    $hGUI = GUICreate("", 250, 250)

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

    $Combobox = GUICtrlCreateCombo("", 10, 10, 100, 120, $CBS_DROPDOWNLIST)
    GUICtrlSetOnEvent($Combobox, "_Combo")
    $hComboBox = GUICtrlGetHandle($Combobox)
    $eButton = GUICtrlCreateButton("Enter", 140, 8, 75, 25, $BS_FLAT)
    $hList = GUICtrlCreateList("", 10, 50, 230, 190, $WS_VSCROLL + $LBS_SORT)
    ; GUICtrlSetOnEvent($eButton,"Enter")
    GUISetOnEvent($GUI_EVENT_CLOSE, "End")
    GUISetState(@SW_SHOW)

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

    Dim $aRecords
    If Not _FileReadToArray("liste.txt", $aRecords) Then
    MsgBox(4096, "Error", " Error reading log to Array error:" & @error)
    Exit
    EndIf

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

    Dim $ttsystems
    If Not _FileReadToArray("ttsystem.txt", $ttsystems) Then
    MsgBox(4096, "Error", " Error reading log to Array error:" & @error)
    Exit
    EndIf

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

    Dim $maps
    If Not _FileReadToArray("liste2.txt", $maps) Then
    MsgBox(4096, "Error", " Error reading log to Array error:" & @error)
    Exit
    EndIf

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

    Dim $meta
    If Not _FileReadToArray("meta.txt", $meta) Then
    MsgBox(4096, "Error", " Error reading log to Array error:" & @error)
    Exit
    EndIf

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

    For $x = 1 To $aRecords[0]
    _GUICtrlComboBox_AddString($hComboBox, $aRecords[$x])
    Next

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

    While 1
    Sleep(50)
    WEnd
    Func _Combo()
    If _GUICtrlComboBox_GetCurSel($hComboBox) = 0 Then
    _GUICtrlListBox_ResetContent($hList)
    For $x = 1 To $maps[0]
    _GUICtrlListBox_AddString($hList, $maps[$x])
    Next
    _GUICtrlComboBox_SetCurSel($hComboBox, -1)
    EndIf
    If _GUICtrlComboBox_GetCurSel($hComboBox) = 1 Then
    _GUICtrlListBox_ResetContent($hList)
    For $x = 1 To $ttsystems[0]
    _GUICtrlListBox_AddString($hList, $ttsystems[$x])
    Next
    _GUICtrlComboBox_SetCurSel($hComboBox, -1)
    EndIf
    EndFunc ;==>_Combo
    Func End()
    Exit
    EndFunc ;==>End

    [/autoit]

    Hab ausversehen GuiSetOnEvent anstatt GUICtrlSetOnEvent verwendet , so sollte es funktionieren

    Edit das Sleep(1000) ist unnütz, Quellcode angepaßt.