Listview filtern

  • Hallo!

    Ich würde gerne eine in einer listview filtern. Dazu habe ich folgendes Script im englischen Forum gefunden.

    Spoiler anzeigen
    [autoit]


    #include <Constants.au3>
    #include <GUIConstants.au3>
    #include <WindowsConstants.au3>
    #include <GUIListView.au3>
    #include <WinAPI.au3>

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

    $gui = GUICreate("listview filter", 400, 250, -1, -1)
    $listview = GUICtrlCreateListView("col0|col1|col2", 10, 10, 380, 230)
    GUICtrlSendMsg(-1, 0x101E, 0, 125)
    GUICtrlSendMsg(-1, 0x101E, 1, 125)
    GUICtrlSendMsg(-1, 0x101E, 2, 125)
    GUICtrlCreateListViewItem("blue|green|blue", $listview)
    GUICtrlCreateListViewItem("red|blue|green", $listview)
    GUICtrlCreateListViewItem("green|red|red", $listview)
    GUICtrlCreateListViewItem("blue|green|blue", $listview)
    GUICtrlCreateListViewItem("red|blue|green", $listview)
    GUICtrlCreateListViewItem("green|red|red", $listview)
    GUICtrlCreateListViewItem("blue|green|blue", $listview)
    GUICtrlCreateListViewItem("red|blue|green", $listview)
    GUICtrlCreateListViewItem("green|red|red", $listview)
    GUICtrlCreateListViewItem("blue|green|blue", $listview)
    GUICtrlCreateListViewItem("red|blue|green", $listview)
    GUICtrlCreateListViewItem("green|red|red", $listview)
    GUISetState()

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

    ;Use of lock/unlock and begin/end update is just to cause repainting so the filterbar is fully visible
    GUISetState(@SW_LOCK, $gui)
    _GUICtrlListView_BeginUpdate($listview)

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

    ;Add the filter bar to the header control
    $header = _GUICtrlListView_GetHeader($listview)
    $styles = _WinAPI_GetWindowLong($header, $GWL_STYLE)
    _WinAPI_SetWindowLong($header, $GWL_STYLE, BitOR($styles, $HDS_FILTERBAR))

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

    ;Use of lock/unlock and begin/end update is just to cause repainting so the filterbar is fully visible
    _GUICtrlListView_EndUpdate($listview)
    GUISetState(@SW_UNLOCK, $gui)

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

    ;Register WM_NOTIFY to handle $HDN_FILTERBTNCLICK messages
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

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

    ;Loop GUI until exit
    Do
    $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE

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

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode
    Local $tNMHDR, $tNMHEADER, $tNMHDFILTERBTNCLICK, $tNMHDDISPINFO
    Local $iHeaderItem, $tItem
    Local $HDFT_ISSTRING = 0x0
    Local $HDFT_ISNUMBER = 0x1

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

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $header
    Switch $iCode
    Case $HDN_FILTERBTNCLICK ; Notifies the header control's parent window when the filter button is clicked or in response to an $HDM_SETITEM message
    $tNMHDFILTERBTNCLICK = DllStructCreate($tagNMHDFILTERBTNCLICK, $ilParam)
    $column = DllStructGetData($tNMHDFILTERBTNCLICK, "Item")
    MsgBox(0, "Msg", "Filter button click for column " & $column & @CRLF & _
    "Now I need code for getting the filter text!")

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

    ;Return True ; An $HDN_FILTERCHANGE notification will be sent to the header control's parent window
    ; This notification gives the parent window an opportunity to synchronize its user interface elements
    Return False ; If you do not want the notification sent
    Case $HDN_FILTERCHANGE ; Notifies the header control's parent window that the attributes of a header control filter are being changed or edited
    ;$tNMHEADER = DllStructCreate($tagNMHEADER, $ilParam)
    ; no return value
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]

    Leider hat dort keiner auf die Frage des Erstellers des Scripts geantwortet.
    Ich hoffe ihr könnt mir helfen.
    Die WM_Notify Funktion wertet einen Druck auf die Buttons der Filterleiste aus.
    Jetzt ist allerdings die Frage wie bekommt man einen eventuell eingegebenen Text in den Textfeldern heraus?
    Mit Winspector erhält man dieses Ergebnis. (Siehe Bildanhang)
    Danke für eure Bemühungen!