Deye Posted February 14, 2017 Share Posted February 14, 2017 (edited) 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 expandcollapse popup#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 February 14, 2017 by Deye Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2017 Moderators Share Posted February 14, 2017 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 Deye 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Deye Posted February 14, 2017 Author Share Posted February 14, 2017 Ok, with some correction to the code above The challenge is to keep showing what's checked when the filter is on for the selected search And when the filter is cleared to keep checked items intact Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2017 Moderators Share Posted February 14, 2017 Deye, Let me see if I understand the requirement: Checked items are to be shown regardless of the filter setting Other items are filtered according to the content of the input Is that correct? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Deye Posted February 14, 2017 Author Share Posted February 14, 2017 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 More sharing options...
Moderators Melba23 Posted February 14, 2017 Moderators Share Posted February 14, 2017 Deye, How about this: expandcollapse popup#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 Deye 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Deye Posted February 14, 2017 Author Share Posted February 14, 2017 Melba, Well done, This works absolutely great! Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now