Jump to content

Search In ListView


Deye
 Share

Recommended Posts

Hi,

I'm trying to filter results from a list and have whats to be checked kept as checked (when clearing the Input filter from the top of the GUI)
strangely I'm now stuck with populating the list for getting this example going .. ^^

will be happy to get some assistants on this one

thanks

Got the example code from Here

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Global $iListView, $iNoCols = 2, $iNoItems = 1000, $aArrData[$iNoItems][$iNoCols], $idInput

Example()

Func Example()

    GUICreate("ListView Original", 350, 500)
    $idInput = GUICtrlCreateInput("", 5, 5, 340)


    $iListView = GUICtrlCreateListView("|", 5, 22, 340, 500 - 55)
    $hListView = GUICtrlGetHandle(-1)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))

    For $i = 1 To $iNoItems
        IniWrite(@ScriptDir & "\sample.ini", "ITEM", "ITEM " & $i, False)
    Next

    $aArrData = IniReadSection(@ScriptDir & "\sample.ini", "ITEM")
    _ArrayDelete($aArrData, 0) ; Remove number of elements from array

    _ArrayDisplay($aArrData)

    _GUICtrlListView_AddArray($iListView, $aArrData)
    _GUICtrlListView_SetColumnWidth($hListView, 0, 160)
    _GUICtrlListView_SetColumnWidth($hListView, 1, 160)


    GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>Example


Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0xFFFF) ;LoWord
    Local $iCode = BitShift($wParam, 16) ;HiWord
    If $iIDFrom = $idInput And $iCode = $EN_CHANGE Then
        _GUICtrlListView_DeleteAllItems($iListView)
        _GUICtrlListView_AddArray($iListView, $aArrData)
        $sFind = GUICtrlRead($idInput)
        If $sFind <> "" Then
            For $i = _GUICtrlListView_GetItemCount($iListView) To 0 Step -1
                $sText = _GUICtrlListView_GetItemText($iListView, $i)
                If StringInStr($sText, $sFind) = 0 Then _GUICtrlListView_DeleteItem($iListView, $i) ; <<<< Apply filter
            Next
        EndIf
    EndIf
EndFunc   ;==>MY_WM_COMMAND

 

Edited by Deye
Link to comment
Share on other sites

  • Moderators

Deye,

You need to set the width of the columns so that there is room for the data to display:

$iListView = GUICtrlCreateListView("|", 5, 22, 340, 500 - 55)
$hListView = GUICtrlGetHandle(-1)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_SetColumnWidth($hListView, 0, 160)
_GUICtrlListView_SetColumnWidth($hListView, 1, 160)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Deye,

Let me see if I understand the requirement:

  1. Checked items are to be shown regardless of the filter setting
  2. Other items are filtered according to the content of the input

Is that correct?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

13 minutes ago, Melba23 said:

Checked items are to be shown regardless of the filter setting

The filter processing can act as usual but mainly show if the item was previously checked
Or as you suggested "show all checked items" when the filter processing is active ..

 

13 minutes ago, Melba23 said:

Other items are filtered according to the content of the input

Not sure I fully understood ..
The filter processing seems to work fine with  the example above

Link to comment
Share on other sites

  • Moderators

Deye,

How about this:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Global $iListView, $iNoCols = 2, $iNoItems = 1000, $aArrData[$iNoItems][$iNoCols], $idInput, $fFilter = False

For $i = 1 To $iNoItems
    IniWrite(@ScriptDir & "\sample.ini", "ITEM", "ITEM " & $i, False)
Next

Example()

Func Example()

    GUICreate("ListView Original", 350, 500)
    $idInput = GUICtrlCreateInput("", 5, 5, 340)


    $iListView = GUICtrlCreateListView("|", 5, 22, 340, 500 - 55)
    _GUICtrlListView_SetExtendedListViewStyle($iListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
    _GUICtrlListView_SetColumnWidth($iListView, 0, 160)
    _GUICtrlListView_SetColumnWidth($iListView, 1, 160)

    $aArrData = IniReadSection(@ScriptDir & "\sample.ini", "ITEM")

    _ArrayDelete($aArrData, 0) ; Remove number of elements from array

    _GUICtrlListView_AddArray($iListView, $aArrData)

    GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch

        If $fFilter Then
            $fFilter = False
            _Filter()
        EndIf

    WEnd

EndFunc   ;==>Example

Func _Filter()
    ; Get full array
    $aArrData = IniReadSection(@ScriptDir & "\sample.ini", "ITEM")
    ; gte required search string
    $sFind = GUICtrlRead($idInput)
    ; List of items to delete - quicker to do it all in one go
    $sDeleteRange = "0"
    ; Get list of text of checked items
    $sCheckedItems = "|"
    For $i = 0 To _GUICtrlListView_GetItemCount($iListView) - 1
        If _GUICtrlListView_GetItemChecked($iListView, $i) Then
            $sCheckedItems &= "|" & _GUICtrlListView_GetItemText($iListView, $i) & "|"
        EndIf
    Next
    ; See if there an input to check against
    If $sFind <> "" Then
        ; Loop through array
        For $i = 1 To $aArrData[0][0]
            ; Get item text
            $sItem = $aArrData[$i][0]
            ; Clear delete flag
            $fDelete = False
            ; If item does not match - possible delete
            If Not StringInStr($sItem, $sFind) Then
                ; Check if item checked in ListView
                $iIndex = _GUICtrlListView_FindText($iListView, $sItem)
                If $iIndex = -1 Then
                    ; Not in ListView so cannot be checked - delete
                    $fDelete = True
                Else
                    ;See if checked
                    If Not _GUICtrlListView_GetItemChecked($iListView, $iIndex) Then
                        ; If not checked - delete
                        $fDelete = True
                    EndIf
                EndIf

                ; if item to be deleted add to list
                If $fDelete Then
                    $sDeleteRange &= ";" & $i
                EndIf
            EndIf
        Next
    EndIf

    ; ; Delete all items in one go
    _ArrayDelete($aArrData, $sDeleteRange)

    ; Redraw ListView
    _GUICtrlListView_DeleteAllItems($iListView)
    _GUICtrlListView_AddArray($iListView, $aArrData)

    ; Reset check marks to already checked items
    For $i = 0 To _GUICtrlListView_GetItemCount($iListView) - 1
        If StringInStr($sCheckedItems, "|" & _GUICtrlListView_GetItemText($iListView, $i) & "|") Then
            _GUICtrlListView_SetItemChecked($iListView, $i)
        EndIf
    Next

EndFunc   ;==>_Filter


Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0xFFFF) ;LoWord
    Local $iCode = BitShift($wParam, 16) ;HiWord
    If $iIDFrom = $idInput And $iCode = $EN_CHANGE Then
        $fFilter = True
    EndIf
EndFunc   ;==>MY_WM_COMMAND

The filtering takes some time for 1000 lines, which meant that the script risked spending far too long in the handler, so I have removed that part of the code into a separate function.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...