Listbox - Nachladen von daten in eine zweite

  • Hallo zusammen,

    habe ein kleines problem mit einer listbox!

    habe 2 listboxen ...
    listbox 1 wird aus einer textdatei mit daten gefüllt!!!
    wenn ich nun in listbox 1 z.b auf eintrag 5 klicke sollen daten in listbox 2 nachgeladen werden!

    wie löse ich das am besten!

    danke
    vielleicht hat einer eine gute idee!

    gruß gmmg

  • Wäre besser, wenn du dein bisheriges Script posten könntest, aber hier schonmal ein Beispiel zu 3/4 aus der Hilfe!

    Spoiler anzeigen
    [autoit]

    #AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
    #include <GUIListBox.au3>
    #include <GuiConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <Constants.au3>
    #include <Array.au3>
    Opt('MustDeclareVars', 1)

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

    $Debug_LB = False ; Check ClassName being passed to ListBox functions, set to True and use a handle to another control to see it work

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

    Global $hListBox
    _Main()

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

    Func _Main()
    Local $hGUI

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

    ; Create GUI
    $hGUI = GUICreate("(UDF Created) List Box Create", 400, 296)
    $hListBox = _GUICtrlListBox_Create($hGUI, "String upon creation", 2, 2, 396, 296)
    GUISetState()

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

    MsgBox(4160, "Information", "Adding Items")

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

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

    ; Add files
    _GUICtrlListBox_BeginUpdate($hListBox)
    _GUICtrlListBox_ResetContent($hListBox)
    _GUICtrlListBox_InitStorage($hListBox, 100, 4096)
    _GUICtrlListBox_Dir($hListBox, @WindowsDir & "\win*.exe")
    _GUICtrlListBox_AddFile($hListBox, @WindowsDir & "\Notepad.exe")
    _GUICtrlListBox_Dir($hListBox, "", $DDL_DRIVES)
    _GUICtrlListBox_Dir($hListBox, "", $DDL_DRIVES, False)
    _GUICtrlListBox_EndUpdate($hListBox)

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

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    EndFunc ;==>_Main

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

    Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox,$handle,$i
    If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word

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

    Switch $hWndFrom
    Case $hListBox, $hWndListBox
    Switch $iCode
    Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box
    ;~ $handle = GuiCtrlGethandle($hListBox)
    For $i = 1 To _GUICtrlListBox_GetCount($hlistBox)
    If _GUICtrlListBox_GetSel($hListBox, $i) Then ExitLoop
    Next
    MsgBox(0,"SelectedItem",$i)
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_COMMAND

    [/autoit]
  • Hallo : gmmg,

    Wenn es sich nur um wenige Einträge handelt, verfahre genauso wie mir der ListBox1, es muss halt unterschiedliche Textfiles existieren, ein Teil oder der ganze Dateiname solltem dem Eintrag in der Listbox1 entsprechen. Wenn in ListBox1 ein Eintrag ausgewählt wird, löcht du zuerst alle Einträge in ListBo2 und füllst sie dann mit den Werten des Textfiles.
    Bei größeren Datenmengen solltest du dir überlegen, das ganze (auch die Daten für die ListBox1) in einer Datenbank abzulegen und von dort aus die ListBoxen befüllen,

    mfg (Auto)Bert

  • hallo,

    danke für die infos!
    hier mein bisheriges script:

    Spoiler anzeigen
    [autoit]


    #include <File.au3>
    #include <GUIConstants.au3>
    #Include <Array.au3>
    ;#include <ADFunctions.au3>

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

    $file = ("\\server\NETLOGON\Portale_Erfassungsbogen\portale.txt")
    Dim $aRecords
    Dim $sString
    If Not _FileReadToArray($file,$aRecords) Then
    MsgBox(4096,"Error", " Error reading log to Array error:" & @error)
    Exit
    EndIf

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

    For $x = 1 to $aRecords[0]
    ; Msgbox(0,'Record:' & $x, $aRecords[$x])
    ;Next

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

    $sString &= $aRecords[$x]
    Next
    ;MsgBox(0,"", $sString)

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

    $DATAC1 = "Angebot|Rückfrage|Stornierung|Umbuchung|RSB Buchung"
    $DATAC2 = $sString

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

    $Form1 = GUICreate("Erfassungsbogen 3.0.1", 740, 530, 219, 137)
    ;$Label1 = GUICtrlCreateLabel("Portal", 16, 16, 39, 20)
    ;GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label2 = GUICtrlCreateLabel("Name", 16, 64, 41, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("Grund des Anrufes", 16, 40, 114, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label4 = GUICtrlCreateLabel("Telefon", 16, 92, 50, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label5 = GUICtrlCreateLabel("E-Mail", 16, 112, 42, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label6 = GUICtrlCreateLabel("Veranstalter", 16, 136, 76, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label7 = GUICtrlCreateLabel("Vorgang", 16, 160, 56, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label8 = GUICtrlCreateLabel("Fakten", 16, 184, 45, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    ;$Input1 = GUICtrlCreateInput("", 136, 16, 249, 21)
    $Combo1 = GUICtrlCreateCombo(" ... Bitte auswählen", 136, 40, 249, 25)
    GUICtrlSetData(-1, $DATAC1)
    $Input2 = GUICtrlCreateInput("", 136, 64, 249, 21)
    $Input3 = GUICtrlCreateInput("", 136, 88, 249, 21)
    $Input4 = GUICtrlCreateInput("", 136, 112, 249, 21)
    $Input5 = GUICtrlCreateInput("", 136, 136, 249, 21)
    $Input6 = GUICtrlCreateInput("", 136, 160, 249, 21)
    $Edit1 = GUICtrlCreateEdit("", 408, 16, 305, 249)
    GUICtrlSetData(-1, "")
    ;$Group1 = GUICtrlCreateGroup("Group1", 304, 40, 1, 9)
    ;GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Edit2 = GUICtrlCreateEdit("", 136, 184, 249, 81)
    GUICtrlSetData(-1, "")
    $Group2 = GUICtrlCreateGroup("ITYX", 16, 272, 497, 249)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $List1 = GUICtrlCreateList("", 32, 296, 249, 214)
    GUICtrlSetData(-1, $DATAC2)
    $List2 = GUICtrlCreateList("", 296, 296, 201, 214)
    GUICtrlSetData(-1, "")
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("Löschen", 584, 392, 97, 25, 0)
    $Button2 = GUICtrlCreateButton("Senden", 584, 432, 97, 25, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

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

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

    EndSwitch
    WEnd

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

    hier mal meine lösung mit daten aus einer access DB

    Spoiler anzeigen
    [autoit]


    #include <File.au3>
    #include <GUIConstants.au3>
    #Include <Array.au3>
    ;#include <ADFunctions.au3>

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

    $file = (@ScriptDir & "\portale.txt")
    Dim $aRecords
    Dim $sString
    If Not _FileReadToArray($file,$aRecords) Then
    MsgBox(4096,"Error", " Error reading log to Array error:" & @error)
    Exit
    EndIf

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

    For $x = 1 to $aRecords[0]
    ; Msgbox(0,'Record:' & $x, $aRecords[$x])
    ;Next

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

    $sString &= $aRecords[$x]
    Next
    ;MsgBox(0,"", $sString)

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

    ;$DATAC1 = $line
    $DATAC1 = "Angebot|Rückfrage|Stornierung|Umbuchung|RSB Buchung"
    $DATAC2 = $sString

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

    $Form1 = GUICreate("Erfassungsbogen 3.0.1", 740, 530, 219, 137)
    ;$Label1 = GUICtrlCreateLabel("Portal", 16, 16, 39, 20)
    ;GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label2 = GUICtrlCreateLabel("Name", 16, 64, 41, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("Grund des Anrufes", 16, 40, 114, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label4 = GUICtrlCreateLabel("Telefon", 16, 92, 50, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label5 = GUICtrlCreateLabel("E-Mail", 16, 112, 42, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label6 = GUICtrlCreateLabel("Veranstalter", 16, 136, 76, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label7 = GUICtrlCreateLabel("Vorgang", 16, 160, 56, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label8 = GUICtrlCreateLabel("Fakten", 16, 184, 45, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    ;$Input1 = GUICtrlCreateInput("", 136, 16, 249, 21)
    $Combo1 = GUICtrlCreateCombo(" ... Bitte auswählen", 136, 40, 249, 25)
    GUICtrlSetData(-1, $DATAC1)
    $Input2 = GUICtrlCreateInput("", 136, 64, 249, 21)
    $Input3 = GUICtrlCreateInput("", 136, 88, 249, 21)
    $Input4 = GUICtrlCreateInput("", 136, 112, 249, 21)
    $Input5 = GUICtrlCreateInput("", 136, 136, 249, 21)
    $Input6 = GUICtrlCreateInput("", 136, 160, 249, 21)
    $Edit1 = GUICtrlCreateEdit("", 408, 16, 305, 249)
    GUICtrlSetData(-1, "")
    ;$Group1 = GUICtrlCreateGroup("Group1", 304, 40, 1, 9)
    ;GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Edit2 = GUICtrlCreateEdit("", 136, 184, 249, 81)
    GUICtrlSetData(-1, "")
    $Group2 = GUICtrlCreateGroup("ITYX", 16, 272, 497, 249)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $List1 = GUICtrlCreateList("", 32, 296, 249, 214)
    GUICtrlSetData(-1, $DATAC2)
    $List2 = GUICtrlCreateList("", 296, 296, 201, 214)
    GUICtrlSetData(-1, "")
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("Löschen", 584, 392, 97, 25, 0)
    $Button2 = GUICtrlCreateButton("Senden", 584, 432, 97, 25, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    ;========================================================
    ; Modify the variables below as desired or applicable
    ; ******************************************************
    $dbname = @ScriptDir & "\portale.mdb"

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

    $tblname_1 = "Portale"
    ;===========================================
    ; table 01_MA
    ;===========================================
    $fldname_tbl1_1 = "projekt"
    $format = "Text(100)"
    $fldname_tbl1_2 = "teilprojekt"
    $format = "Text(100)"
    $fldname_tbl1_3 = "mail"
    $format = "Text(150)"

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

    ;$query2 = "SELECT * FROM "& $tblname_1 & " WHERE PC = " & "'" & @UserName & "'"
    ;$strData2 = _ReadOneFld($query1, $dbname, $fldname_tbl1_2) ; db auslesen = pc abhängig

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

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

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

    ;~ If GUICtrlRead($List1) = "abocard" Then
    ;~ GUICtrlSetData($List2, "")
    ;~ GUICtrlSetData($List2, "A1|A3|A3")
    ;~ EndIf
    ;If GUICtrlRead($List1) = "abocard" Then GUICtrlSetData($List2, $DATAC2)

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

    $wert1 = GUICtrlRead($List1)
    $query1 = "SELECT * FROM "& $tblname_1 & " WHERE projekt = " & "'" & $wert1 & "'"
    $strData1 = _ReadOneFld($query1, $dbname, $fldname_tbl1_2) ; db auslesen

    ;MsgBox(64,"", StringStripWS($strData1,3)) ;leerzeichen abschneiden
    ;MsgBox(0,"",$strData1)

    GUICtrlSetData($List2, "")
    GUICtrlSetData($List2, StringStripWS($strData1,3))

    Case $Button1
    Case $Button2

    EndSwitch
    WEnd

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

    Func _ReadOneFld($_sql, $_dbname, $_field)
    Dim $_output
    $adoCon = ObjCreate ("ADODB.Connection")
    $adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $_dbname)
    $adoRs = ObjCreate ("ADODB.Recordset")
    $adoRs.CursorType = 1
    $adoRs.LockType = 3
    $adoRs.Open ($_sql, $adoCon)

    With $adoRs
    If .RecordCount Then
    While Not .EOF
    $_output = $_output & .Fields ($_field).Value & @CRLF
    .MoveNext
    WEnd
    EndIf
    EndWith
    $adoCon.Close
    Return $_output
    EndFunc ;==>_ReadOneFld

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

    vielleicht noch einer ne andere möglichkeit?

    danke u. gruß

    gmmg

    Einmal editiert, zuletzt von gmmg (28. Mai 2009 um 08:55)