Jump to content

_GUICtrlListBox_FindInText to find the next occurencece


Recommended Posts

All,

I created a listbox based on an existing forum post. I've changed _GUICtrlListBox_FindString in the example to _GUICtrlListBox_FindInText as I needed to search on any position of the listbox line, and not only from the beginning. It works, but - it doesn't know how to proceed to the next occurrence: it always retrieves the first occurrence from the top, although I've set the parameter -1 as the 3rd parameter, believing it will search from the selected line - but it doesn't do it.

Any idea?

Thanks a lot

Bruno

testsearchlistbox.au3

Link to comment
Share on other sites

Try this change to your script.

#include <ButtonConstants.au3>
#include <file.au3>
#include <GUIListBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>





#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("TextExpander", 451, 403, 336, 33)
$IP = GUICtrlCreateInput("", 32, 304, 177, 21)
; GUICtrlCreateInput("", 240, 304, 177, 21)
$Button1 = GUICtrlCreateButton("OK", 24, 344, 89, 33, $BS_DEFPUSHBUTTON)
$Button2 = GUICtrlCreateButton("Add Entry", 136, 344, 105, 33)
$Edit1 = GUICtrlCreateList("", 16, 8, 409, 279)
$Button3 = GUICtrlCreateButton("Close", 352, 344, 65, 33)
GUISetState(@SW_SHOW)
LoadData()
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

Func LoadData()
     Local Const $sFilePath = @ScriptDir & "\Textexpander.txt"
     Local $hFileOpen = FileOpen($sFilePath, $FO_READ)
     $sData = FileRead($hFileOpen)
     FileClose($hFileOpen)
     Global $MyVal = StringSplit($sData, "|")
     Global $possibles = StringReplace($sData, @CRLF, '|')
     GUICtrlSetData($Edit1, $possibles)
EndFunc   ;==>LoadData


While 1
     $msg = GUIGetMsg()
     If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

     Local $hdlWindowFrom, _
               $intControlID_From, _
               $intMessageCode, _
               $strSearchString = ""
     Static $intItemIndex = -1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


     $intControlID_From = BitAND($wParam, 0xFFFF)
     $intMessageCode = BitShift($wParam, 16)

     Switch $intControlID_From
          Case $IP

               Switch $intMessageCode
                    Case $EN_CHANGE

                         $strSearchString = GUICtrlRead($IP)
                         $intItemIndex = _GUICtrlListBox_FindInText($Edit1, $strSearchString, $intItemIndex + 1) ; <<<<<<<<<<<<<<
                         If @error Then
                              ConsoleWrite("Error while searching the string in the ListBox. Error: " & @error & @CRLF)
                         Else
                              _GUICtrlListBox_SetCurSel($Edit1, $intItemIndex)
                              If @error Then
                                   ConsoleWrite("Error while selecting the ListBox Item " & $intItemIndex & ".Error: " & @error & @CRLF)
                              EndIf
                         EndIf

               EndSwitch

     EndSwitch

EndFunc   ;==>WM_COMMAND

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks BrewManMH! I've tried it, and it improves the script but...

Let me explain the data structure. The search example is on the word "caccia" which means "hunt". 

I press "c" the first time and it highlights ABB010 abbandono cani gatti, cause it's the first line containing "c"

Then I press "a" and it proceeds to the ADO010 adozioni cani, as it contains the "ca". Already there, the behavior is weird - the previous hit also contains "ca".

Anyway, I press "c" and it proceeds to AFR001 fiere caccia

I press "c" again and it proceeds to AFR003 fiere caccia pesca

I press "i" and it proceeds to CCC000 caccia generale

I press "a" and it proceeds to CCC002 caccia disturbo venatorio - the 4th item that contains the complete search term.

Now, the list contains other 9 lines with "caccia", but there's no way to select them - as I do not have the "Next" button, and no other letters to type.

Conclusion: instead to make it jump to the next occurrence on any new letter contained in the search term, I would expect a way to have the "Next" button to make it proceed. Such solution would allow to proceed to the next occurrence also when the search term is complete and there are other lines below containing it.

Is there a way to achieve it?

PS. I attached the example of list I'm using to test.

Thanks a lot

Bruno 

datastructure.jpg

textexpander.txt

Link to comment
Share on other sites

All,

I believe I've found a solution - not elegant but working.

Attached the modified script with the Next button and the following behavior: while typing a search term, the selection jumps as in the BrewManMH's version, and - as in the BrewManMH's version - stops to jump when the search term is complete.

Then, pressing the Next button, it jumps to the next occurrences of the search term (while any).

When it reaches the last occurrence, it jumps to the the first complete occurrence and then it cycles down.

The AutoIt capabilities are really amazing!

Bruno

testsearchlistbox3.au3

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...