Jump to content
Sign in to follow this  
johnmcloud

Search in ListView

Recommended Posts

johnmcloud

Hi,

This is a example script:

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIDataSeparatorChar", "/")
$GUI = GUICreate("Form1", 673, 433, -1, -1)
$hListView = GUICtrlCreateListView("Name File / Value", 8, 64, 657, 361)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 380)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 270)
$Button1 = GUICtrlCreateButton("Load", 8, 16, 105, 33)
$Input1 = GUICtrlCreateInput("Input1", 136, 24, 145, 21)
$Button2 = GUICtrlCreateButton("Search", 304, 16, 105, 33)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$Log = "Test1/Test" & @LF & "Test2/Sun" & @LF & "Sun1/Sun/" & @LF & "Earth1/Earth1"
$aArray = StringSplit($Log, @LF)
For $i = 1 To $aArray[0]
GUICtrlCreateListViewItem($aArray[$i], $hListView)
Next
EndSwitch
WEnd

I want to add a seach module for show only certain string, exmple if i write in the inputbox:

"Te"

I want to display:

Test1

Test2

Or if i write Test1 i want ti see only Test1

Side Question

Resolved, stupid question

Thanks for any help :D

Edited by johnmcloud

Share this post


Link to post
Share on other sites
Melba23

johnmcloud,

Place all the values into an array and then use the EN_CHANGE message to detect a change in the input. Delete all the existing ListView items, search the array for the required text and rewrite any found items back into the ListView. :)

You might find some of the code in this thread to be helpful as it does much the same sort of thing. ;)

Give it a go and see how you get on - you know where we are if you run into problems. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
PlayHD

#include 
#include 
#include 
#include 
Opt("GUIDataSeparatorChar", "/")
$GUI = GUICreate("Form1", 673, 433, -1, -1)
$hListView = GUICtrlCreateListView("Name File / Value", 8, 64, 657, 361)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 380)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 270)
$Button1 = GUICtrlCreateButton("Load", 8, 16, 105, 33)
$Input1 = GUICtrlCreateInput("Input1", 136, 24, 145, 21)
$Button2 = GUICtrlCreateButton("Search", 304, 16, 105, 33)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$Log = "Test1/Test" & @LF & "Test2/Sun" & @LF & "Sun1/Sun/" & @LF & "Earth1/Earth1"
$aArray = StringSplit($Log, @LF)
For $i = 1 To $aArray[0]
GUICtrlCreateListViewItem($aArray[$i], $hListView)
Next
Case $Button2
$search = _GuiCtrlListView_ItemSearch($hListView,GUICtrlRead($Input1))
If $search <> -1 Then
MsgBox(64,"_GuiCtrlListView_ItemSearch","String found at "&@LF&"Line : "&$search+1&@LF&"Col : "&@extended+1)
ElseIf @error
MsgBox(16,"_GuiCtrlListView_ItemSearch","Error : "&@error)
Else
MsgBox(48,"_GuiCtrlListView_ItemSearch","String not found!")
EndIf
EndSwitch
WEnd


; #FUNCTION# ====================================================================================================================
; Name ..........: _GuiCtrlListView_ItemSearch
; Description ...: Search a text in a listview(limited in first result)
; Syntax ........: _GuiCtrlListView_ItemSearch($ctrlId, $sSearch[, $sReturnPosition = True[, $sCaseSense = False]])
; Parameters ....: $ctrlId - Control ID from listview.
; $sSearch - String to search.
; $sReturnPosition - [optional] Returning position or just True/False.
; $sCaseSense - [optional] If function use case sensitive or not.
; Return values .: Succes : $sReturnPosition = True -> Line of text (zero based) and set @extended to subitem (zero based)
; $sReturnPosition = False -> True
; Faile : $sReturnPosition = True -> -1
; $sReturnPosition = False -> False
; Wrong parameters : Return -2 and set @error to:
; >1 : No items in listview
; >2 : No column in listview
; >3 : $sSearch is empty ("")
; Author ........: PlayHD (Ababei Andrei)
; Modified ......: -
; Remarks .......: The function is limited in first result.
; Related .......: _GUICtrlListView_GetItemText
; Link ..........: No
; Example .......: Yes
; ===============================================================================================================================
Func _GuiCtrlListView_ItemSearch($ctrlId,$sSearch,$sReturnPosition = True, $sCaseSense = False)
If $sSearch = "" Then Return SetError(1,0,-2)
Local $iCount = _GUICtrlListView_GetItemCount($ctrlId)
If $iCount <= 0 Then Return SetError(2,0,-2)
Local $iCol = _GUICtrlListView_GetColumnCount($ctrlId)
If $iCol <= 0 Then Return SetError(3,0,-2)
Local $i, $j, $lCaseSense = 0
If $sCaseSense = True Then $lCaseSense = 1
For $i = 0 To $iCount
For $j = 0 To $iCol
If StringCompare (_GUICtrlListView_GetItemText($ctrlId,$i,$j),$sSearch,$lCaseSense) = 0 Then
If $sReturnPosition = False Then Return True
Return SetError(0,$j,$i)
EndIf
Next
Next
If $sReturnPosition = False Then Return False
Return SetError(0,0,-1)
EndFunc ;==> _GuiCtrlListView_ItemSearch

Read the header of function..

Share this post


Link to post
Share on other sites
johnmcloud

Hi Melba and PlayHD,

For what i have seen both function are limited to only 1 result, maybe the Melba's script can be edited with a list or result, because a need i list of result ;)

Thanks

Edited by johnmcloud

Share this post


Link to post
Share on other sites
Torni

would it not better to use

If StringInStr (_GUICtrlListView_GetItemText($ctrlId,$i,$j),$sSearch,$lCaseSense) <> 0 Then

instead of StringCompare to search for part of a String??

Share this post


Link to post
Share on other sites
Melba23

johnmcloud,

Check the script in post #9 of that thread as it returns all the matches as you want. ;)

I will be happy to help you work on the problem, but please do have a go at coding something yourself first. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
johnmcloud

@Melba

You have right, but i have some difficulties, i'll check it out better. With the second script i see only the tab of the folder and anything else, the first script work but only for one result...and i don't know how to add only the correct result

@PlayHD

Sorry but not work with string like "Te" ( i don't see anything ), instead to show 2 result. It's better to remove the ArrayDisplay and make directly the result in the ListView

Edited by johnmcloud

Share this post


Link to post
Share on other sites
johnmcloud

Sorry but not work, this time give me 3 result for "Te"

Melba save us! :idiot:

Share this post


Link to post
Share on other sites
guinness

Sorry but not work, this time give me 3 result for "Te"

Melba save us! :idiot:

Melba23 did point out to try yourself first.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
johnmcloud

@guinnes i know, what do you think i'm doing? I'm not twiddling my thumbs :D

@PlayHD Wait, i need only the "Name File" column, I did not know he was finding also in the second column.

Share this post


Link to post
Share on other sites
PlayHD

@PlayHD Wait, i need only the "Name File" column, I did not know he was finding also in the second column.

so I think this is the solution, if you need just "name file" put under coment lines :

For $j = 0 To $iCol

and

Next

And use $Array[n][0]

Share this post


Link to post
Share on other sites
johnmcloud

After that, how to display only the matching value? I need to use:

_GUICtrlListView_DeleteAllItems

_GUICtrlListView_AddItem

But i don't have idea how to correctly make an array and add the right matching value. I'm really sorry that you're losing time with this

Edited by johnmcloud

Share this post


Link to post
Share on other sites
Melba23

johnmcloud,

As requested: :D

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

#include <GuiListView.au3>

Opt("GUIDataSeparatorChar", "/")

Global $aData[4][2] = [["Test1", "Test"], ["Test2", "Sun"], ["Sun1", "Sun"], ["Earth1", "Earth1"]]

$hGUI = GUICreate("Form1", 673, 433, -1, -1)
$cListView = GUICtrlCreateListView("Name File / Value", 8, 64, 657, 361)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 380)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 270)
$cButton_Load = GUICtrlCreateButton("Load", 8, 16, 105, 33)
$cInput = GUICtrlCreateInput("", 136, 24, 145, 21)
GUICtrlSendMsg(-1, $EM_SETCUEBANNER, True, "Search...")
$cButton_Search = GUICtrlCreateButton("Search", 304, 16, 105, 33)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_Search
            ; Remove all items
            _GUICtrlListView_DeleteAllItems($cListView)
            ; Is there anything in the input?
            $sText = GUICtrlRead($cInput)
            If StringLen($sText) <> 0 Then
                ; Create a list of matches
                Local $aMatch_List[1] = [0]
                $iStart = 1
                For $i = 0 To UBound($aData) - 1
                    ; Look for the match
                    If StringInStr($aData[$i][0], $sText) Then
                        ; Add to list
                        $aMatch_List[0] += 1
                        ReDim $aMatch_List[$aMatch_List[0] + 1]
                        $aMatch_List[$aMatch_List[0]] = $aData[$i][0] & "/" & $aData[$i][0]
                    EndIf
                Next
                ; Add matches to ListView
                For $i = 1 To $aMatch_List[0]
                    GUICtrlCreateListViewItem($aMatch_List[$i], $cListView)
                Next
            Else
                ; Reload everything
                ContinueCase
            EndIf
        Case $cButton_Load
            ; Remove all items
            _GUICtrlListView_DeleteAllItems($cListView)
            For $i = 0 To UBound($aData) - 1
                GUICtrlCreateListViewItem($aData[$i][0] & "/" & $aData[$i][0], $cListView)
            Next

    EndSwitch
WEnd

But you have to start doing some work - next time I will demand to see some code from you first. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
johnmcloud

But you have to start doing some work - next time I will demand to see some code from you first. ;)

M23

I'm doing some work, i'm here from 3.29PM...spend much time searching/try to understand your funcion of post #9, i don't know why i don't see nothing except tabs

And always post a code before make a thread, if need.

Anyway, thanks for the script but i have a problem lol

$Log = FileRead(@WorkingDir & "temp.rtf")
Global $aData = StringSplit($Log, @LF)

I have removed the $aData[$i][0] to $aData[$i], i can load value but the search not work

EDIT: Sorry it's only slow becouse i have 50000 value, my mistake

Edited by johnmcloud

Share this post


Link to post
Share on other sites
Melba23

johnmcloud,

Look how the array is formatted in my script and how it formatted after your StringSplit, assuming your file gives you the same format as your first post: ;)

Me:  2D array ["Test1", "Test"]

You: 1D array [Test1/Test]

So you will need to change the code to match. As I want to watch a TV programme about Voyager in a while, I will give you the code directly as I will not be around to answer questions later:

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

#include <GuiListView.au3>

Opt("GUIDataSeparatorChar", "/")

; Simulate the StingSplit
Global $aData[4] = ["Test1/Test", "Test2/Sun", "Sun1/Sun", "Earth1/Earth1"]

$hGUI = GUICreate("Form1", 673, 433, -1, -1)
$cListView = GUICtrlCreateListView("Name File / Value", 8, 64, 657, 361)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 380)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 270)
$cButton_Load = GUICtrlCreateButton("Load", 8, 16, 105, 33)
$cInput = GUICtrlCreateInput("", 136, 24, 145, 21)
GUICtrlSendMsg(-1, $EM_SETCUEBANNER, True, "Search...")
$cButton_Search = GUICtrlCreateButton("Search", 304, 16, 105, 33)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_Search
            ; Remove all items
            _GUICtrlListView_DeleteAllItems($cListView)
            ; Is there anything in the input?
            $sText = GUICtrlRead($cInput)
            If StringLen($sText) <> 0 Then
                ; Create a list of matches
                Local $aMatch_List[1] = [0]
                $iStart = 1
                For $i = 0 To UBound($aData) - 1
                    ; Look for the match
                    If StringInStr($aData[$i], $sText) Then
                        ; Add to list
                        $aMatch_List[0] += 1
                        ReDim $aMatch_List[$aMatch_List[0] + 1]
                        $aMatch_List[$aMatch_List[0]] = $aData[$i]
                    EndIf
                Next
                ; Add matches to ListView
                For $i = 1 To $aMatch_List[0]
                    GUICtrlCreateListViewItem($aMatch_List[$i], $cListView)
                Next
            Else
                ; Reload everything
                ContinueCase
            EndIf
        Case $cButton_Load
            ; Remove all items
            _GUICtrlListView_DeleteAllItems($cListView)
            For $i = 0 To UBound($aData) - 1
                GUICtrlCreateListViewItem($aData[$i], $cListView)
            Next
    EndSwitch
WEnd

Note that this code looks for the input text in both columns of the item - if you just want to look in one or the other then you will need to StringSplit the array element before the StringInStr section. ;)

All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
johnmcloud

Yes, i have resolved that problem before your post but thanks for the explaination.

Melba i have a last question. I need to use more than 1 file ( with the same layout ), i have too many value for only one...50.000 or more, so i need to use:

$Log1 = FileRead(@WorkingDir & "temp1.rtf")
$Log2 = FileRead(@WorkingDir & "temp2.rtf")
$Log3 = FileRead(@WorkingDir & "temp3.rtf")
$aArrayLog1 = StringSplit($Log1, @LF)
$aArrayLog2 = StringSplit($Log2, @LF)
$aArrayLog3 = StringSplit($Log3, @LF)
Global $aData = ???

Thanks, as always

Edited by johnmcloud

Share this post


Link to post
Share on other sites
Melba23

johnmcloud,

Yes, i have resolved that problem before your post but thanks for the explaination

Good for you! :thumbsup:

As to the multiple files, I suggest you either make one large array (use _ArrayConcatenate to do this) or use a loop to run through all the arrays. I would try combining the arrays first - looping through the arrays could get a bit messy. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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
Sign in to follow this  

×