In ListView Item suchen ( Alle Spalten oder einzelne) beispiel

  • Ich hab mal was für einen Freund gemacht, ich dachte vieleicht interesiert es euch ja^^ Ich poste es einfach mal!
    Fehler und sowas bitte melden^^

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <ComboConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <ListViewConstants.au3>
    #include <WindowsConstants.au3>
    #Include <GuiListView.au3>

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("ListView", 272, 202, 303, 219)
    $ListView1 = GUICtrlCreateListView("Eins|Zwei|Drei", 2, 2, 266, 150)
    GUICtrlSendMsg(-1, 0x101E, 0, 50)
    GUICtrlSendMsg(-1, 0x101E, 1, 50)
    GUICtrlSendMsg(-1, 0x101E, 2, 50)
    GUICtrlCreateListViewItem("Test|Wie gehts?|Schlecht:-D", $ListView1)
    GUICtrlCreateListViewItem("Hallo|Test|Tag", $ListView1)
    GUICtrlCreateListViewItem("1|2|3", $ListView1)
    GUICtrlCreateListViewItem("4|5|6", $ListView1)
    GUICtrlCreateListViewItem("A|B|C", $ListView1)
    $Button1 = GUICtrlCreateButton("Suchen", 194, 177, 75, 25, 0)
    $Combo1 = GUICtrlCreateCombo("", 2, 154, 266, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
    $Spalten = _Spalten($ListView1)
    GUICtrlSetData ($Combo1,$Spalten[0][0])
    $Input1 = GUICtrlCreateInput("",2,178,190,20)
    $Form2 = GUICreate("Ergebnis", 271, 154, 303, 219)
    $ListView2 = GUICtrlCreateListView("1|2|3", 2, 2, 266, 150)
    GUICtrlSendMsg(-1, 0x101E, 0, 50)
    GUICtrlSendMsg(-1, 0x101E, 1, 50)
    GUICtrlSendMsg(-1, 0x101E, 2, 50)
    GUISetState(@SW_SHOW,$Form1)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[1]
    Case $Form1
    Switch $nMsg[0]
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    $Spalte = GUICtrlRead ($Combo1)
    $Text = GUICtrlRead ($Input1)
    $Suche = _Suche($ListView1,$ListView2,$Text,$Spalte)
    If $Suche Then
    GUISetState(@SW_SHOW,$Form2)
    WinActivate ($Form2)
    Else
    MsgBox (16,"Suche","Es wurde kein Item gefunden")
    EndIf
    EndSwitch
    Case $Form2
    Switch $nMsg[0]
    Case $GUI_EVENT_CLOSE
    GUISetState (@SW_HIDE,$Form2)
    EndSwitch
    EndSwitch
    WEnd

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

    Func _Suche($hWnd,$hWnd2,$Text,$Spalte = "")
    Local $Suche,$SucheText,$TextAll,$Zahl,$Spalten,$sTextAll,$Staus
    Local $Old = -1
    $Staus = False
    _GUICtrlListView_DeleteAllItems($hWnd2)
    $Spalt = _Spalten($ListView1)
    For $B = 1 To UBound($Spalt) -1
    If $Spalt[$B][0] = $Spalte Then
    $Zahl = $Spalt[$B][1]
    ExitLoop
    EndIf
    Next
    While 1
    $TextAll = ""
    $Suche = _GUICtrlListView_FindInText($hWnd, $Text,$Old,False)
    If $Suche <> -1 Then
    $Staus = True
    For $1 = 0 To _GUICtrlListView_GetColumnCount($hWnd) -1
    $SucheText = _GUICtrlListView_GetItemText($hWnd, $Suche,$1)
    If $TextAll <> "" Then
    $TextAll = $TextAll & "|" & $SucheText
    Else
    $TextAll = $SucheText
    EndIf
    Next
    $sTextAll = StringSplit ($TextAll,"|")
    If $Spalte <> "" Then
    If StringInStr ($sTextAll[$Zahl],$Text) <> 0 Then
    GUICtrlCreateListViewItem($TextAll, $hWnd2)
    EndIf
    Else
    GUICtrlCreateListViewItem($TextAll, $hWnd2)
    EndIf
    Local $Old = $Suche
    Else
    ExitLoop
    EndIf
    WEnd
    Return $Staus
    EndFunc
    Func _Spalten($hWnd)
    Local $Spalte,$A,$Index
    $Index = _GUICtrlListView_GetColumnOrderArray($hWnd)
    Local $Spalten[$Index[0]+1][2]
    If IsArray($Index) Then
    For $A = 1 To $Index[0]
    $Spalte = _GUICtrlListView_GetColumn($hWnd, $Index[$A])
    If $Spalten[0][0] = "" Then
    $Spalten[0][0] = $Spalte[5]
    $Spalten[$A][0] = $Spalte[5]
    $Spalten[$A][1] = $A
    Else
    $Spalten[0][0] = $Spalten[0][0] & "|" & $Spalte[5]
    $Spalten[$A][0] = $Spalte[5]
    $Spalten[$A][1] = $A
    EndIf
    Next
    Return $Spalten
    EndIf
    Return False
    EndFunc

    [/autoit]

    Also man könnte das ergebnis natürlich auch noch anders anzeigen lassen und so, aber er brauchte s so^^

    EDIT:
    Kleines Update

    mfg. Jam00

    Einmal editiert, zuletzt von Jam00 (16. Februar 2009 um 19:10)

    • Offizieller Beitrag

    Hm, verstehen nicht ganz warum du 2 LIstviews dafür benutzt. Ausserdem funktioniert die suche nur 1 mal. Beim 2. mal reagiert das ganze nicht mehr.

    • Offizieller Beitrag

    Des sind ja 2 Gui´s 8| Wenn die 2. nicht geschlossen ist und weitergesucht wird dann kommt das Ergebnis zwar in der 2.Gui . Aber die sitzt dann hinter der Hauptgui ;(

    Edit: So is es Übersichtlicher:

    Spoiler anzeigen
    [autoit]

    #include <ComboConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <ListViewConstants.au3>
    #include <WindowsConstants.au3>
    #Include <GuiListView.au3>

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("ListView", 272, 202, 303, 219)
    $ListView1 = GUICtrlCreateListView("Eins|Zwei|Drei", 2, 2, 266, 150)
    GUICtrlSendMsg(-1, 0x101E, 0, 50)
    GUICtrlSendMsg(-1, 0x101E, 1, 50)
    GUICtrlSendMsg(-1, 0x101E, 2, 50)
    GUICtrlCreateListViewItem("Test|Wie gehts?|Schlecht:-D", $ListView1)
    GUICtrlCreateListViewItem("Hallo|Test|Tag", $ListView1)
    GUICtrlCreateListViewItem("1|2|3", $ListView1)
    GUICtrlCreateListViewItem("4|5|6", $ListView1)
    GUICtrlCreateListViewItem("A|B|C", $ListView1)
    $Button1 = GUICtrlCreateButton("Suchen", 194, 177, 75, 25, 0)
    $Combo1 = GUICtrlCreateCombo("", 2, 154, 266, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
    $Spalten = _Spalten($ListView1)
    GUICtrlSetData ($Combo1,$Spalten[0][0])
    $Input1 = GUICtrlCreateInput("",2,178,190,20)
    $Form2 = GUICreate("Ergebnis", 271, 154, 303+278, 219)
    $ListView2 = GUICtrlCreateListView("1|2|3", 2, 2, 266, 150)
    GUICtrlSendMsg(-1, 0x101E, 0, 50)
    GUICtrlSendMsg(-1, 0x101E, 1, 50)
    GUICtrlSendMsg(-1, 0x101E, 2, 50)
    GUISetState(@SW_SHOW,$Form1)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[1]
    Case $Form1
    Switch $nMsg[0]
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    $Spalte = GUICtrlRead ($Combo1)
    $Text = GUICtrlRead ($Input1)
    _Suche($ListView1,$ListView2,$Text,$Spalte)
    EndSwitch
    Case $Form2
    Switch $nMsg[0]
    Case $GUI_EVENT_CLOSE
    GUISetState (@SW_HIDE,$Form2)
    EndSwitch
    EndSwitch
    WEnd

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

    Func _Suche($hWnd,$hWnd2,$Text,$Spalte = "")
    Local $Suche,$SucheText,$TextAll,$Zahl,$Spalten,$sTextAll
    Local $Old = -1
    _GUICtrlListView_DeleteAllItems($hWnd2)
    $Spalt = _Spalten($ListView1)
    For $B = 1 To UBound($Spalt) -1
    If $Spalt[$B][0] = $Spalte Then
    $Zahl = $Spalt[$B][1]
    ExitLoop
    EndIf
    Next
    While 1
    $TextAll = ""
    $Suche = _GUICtrlListView_FindInText($hWnd, $Text,$Old,False)
    If $Suche <> -1 Then
    For $1 = 0 To _GUICtrlListView_GetColumnCount($hWnd) -1
    $SucheText = _GUICtrlListView_GetItemText($hWnd, $Suche,$1)
    If $TextAll <> "" Then
    $TextAll = $TextAll & "|" & $SucheText
    Else
    $TextAll = $SucheText
    EndIf
    Next
    $sTextAll = StringSplit ($TextAll,"|")
    If $Spalte <> "" Then
    If StringInStr ($sTextAll[$Zahl],$Text) <> 0 Then
    GUICtrlCreateListViewItem($TextAll, $hWnd2)
    EndIf
    Else
    GUICtrlCreateListViewItem($TextAll, $hWnd2)
    EndIf
    Local $Old = $Suche
    Else
    ExitLoop
    EndIf
    WEnd
    GUISetState(@SW_SHOW,$Form2)

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

    EndFunc
    Func _Spalten($hWnd)
    Local $Spalte,$A,$Index
    $Index = _GUICtrlListView_GetColumnOrderArray($hWnd)
    Local $Spalten[$Index[0]+1][2]
    If IsArray($Index) Then
    For $A = 1 To $Index[0]
    $Spalte = _GUICtrlListView_GetColumn($hWnd, $Index[$A])
    If $Spalten[0][0] = "" Then
    $Spalten[0][0] = $Spalte[5]
    $Spalten[$A][0] = $Spalte[5]
    $Spalten[$A][1] = $A
    Else
    $Spalten[0][0] = $Spalten[0][0] & "|" & $Spalte[5]
    $Spalten[$A][0] = $Spalte[5]
    $Spalten[$A][1] = $A
    EndIf
    Next
    Return $Spalten
    EndIf
    Return False
    EndFunc

    [/autoit]