Jump to content

Recommended Posts

Posted (edited)

Hello,

is there a good way to search for a string in a listview in upward

direction, starting from an item far down?

I am using _GUICtrlListView_FindInText() to jump to subsequent matches in the

listview and it works great. But I could not find a way to search upwards,

to find the preceding match. I could store all found indexes in an array to

work with, but this is not too elegant.

So maybe this is a request for a search direction parameter for the function

_GUICtrlListView_FindInText(), but I am not sure if this would violate the

general concept of GuiListView.au3, or if Gary thinks this could be needed.

Here is some example code to show what I am trying to do.

Type "ball" in the input box, press down arrow a few times to jump to

next "ball" items.

ciao

Xandl

Edit: added example code.

Edit2: changed example code.

test_lv_FindInText.au3

Edited by Xandl
Posted (edited)

give this a try, I might add the reverse flag in the near future

Func _GUICtrlListView_FindInText($hWnd, $sText, $iStart = -1, $fWrapOK = True, $fReverse = False)
    Local $iI, $iJ, $iCount, $iColumns, $sList

    $iCount = _GUICtrlListView_GetItemCount($hWnd)
    $iColumns = _GUICtrlListView_GetColumnCount($hWnd)
    If $iColumns = 0 Then $iColumns = 1
    
    If $fReverse And $iStart = -1 Then Return -1
    
    If $fReverse Then
        For $iI = $iStart - 1 To 0 Step - 1
            For $iJ = 0 To $iColumns - 1
                $sList = _GUICtrlListView_GetItemText($hWnd, $iI, $iJ)
                If StringInStr($sList, $sText) Then Return $iI
            Next
        Next
    Else
        For $iI = $iStart + 1 To $iCount - 1
            For $iJ = 0 To $iColumns - 1
                $sList = _GUICtrlListView_GetItemText($hWnd, $iI, $iJ)
                If StringInStr($sList, $sText) Then Return $iI
            Next
        Next
    EndIf

    If (($iStart = -1) Or Not $fWrapOK) And Not $fReverse Then Return -1
    
    If $fReverse And $fWrapOK Then
        For $iI = $iCount - 1 To $iStart + 1 Step - 1
            For $iJ = 0 To $iColumns - 1
                $sList = _GUICtrlListView_GetItemText($hWnd, $iI, $iJ)
                If StringInStr($sList, $sText) Then Return $iI
            Next
        Next
    Else
        For $iI = 0 To $iStart - 1
            For $iJ = 0 To $iColumns - 1
                $sList = _GUICtrlListView_GetItemText($hWnd, $iI, $iJ)
                If StringInStr($sList, $sText) Then Return $iI
            Next
        Next
    EndIf

    Return -1
EndFunc   ;==>_GUICtrlListView_FindInText
Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted

Hello,

many thanks for implementing that so fast, it works exactly as expected.

I'll change the above attachment accordingly, to show it.

merci

Xandl

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
  • Recently Browsing   0 members

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