Sign in to follow this  
Followers 0
GEOSoft

_GUIListView UDF Functions

4 posts in this topic

I'm sure there has to be an easy way to do this without looping through the whole ListView control.

I have a Listview with 3 columns.

I have to find out if a given string (exact match except for case sensitivity) exists any place in the second column.

I've tried

_GUICtrlListView_FindInText()

_GUICtrlListView_FindText()

neither of which works although they might if there was an item selected but then they would only check the selected item.

_GUICtrlListView_GetItemText() requires you to loop through each item and that seems totaly insane particularily when it already has to be checked in the Msg Loop to set a button state.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Hey,

This works ok for me using _GUICtrlListView_FindInText to find the row index and then checking the 2nd column of that row using _GUICtrlListView_GetItemText.

Enter search text into the input box and click search and it will display an array of the rows that contain the searched item in column 2.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#include <Array.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
$ListView1 = GUICtrlCreateListView("one|two|three|ColumnPos", 8, 16, 601, 353)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
For $i = 0 To 19 Step 1
    GUICtrlCreateListViewItem(_Something() & "|" & _Something() & "|" & _Something() & "|" & $i, $ListView1)
Next
$Input1 = GUICtrlCreateInput("", 8, 392, 121, 21)
$Button1 = GUICtrlCreateButton("Search", 136, 392, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$hWndListView = GUICtrlGetHandle($ListView1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $sString = ""
            $sReadInput = GUICtrlRead($Input1)
            $iSearchPos = -1
            While 1
            $iFoundPos = _GUICtrlListView_FindInText($hWndListView, $sReadInput, $iSearchPos, False)
            If $iFoundPos > -1 Then
                If _GUICtrlListView_GetItemText($hWndListView, $iFoundPos, 1) = $sReadInput Then $sString &= "|" & $iFoundPos
            Else
                ExitLoop
            EndIf
            $iSearchPos = $iFoundPos
            WEnd
            $aFoundPositions = StringSplit(StringTrimLeft($sString,1),"|")
            _ArrayDisplay($aFoundPositions)
    EndSwitch
WEnd

Func _Something()
    Switch Random(1, 4, 1)
        Case 1
            Return "No"
        Case 2
            Return "Yes"
        Case 3
            Return "Maybe"
        Case 4
            Return "Noway"
    EndSwitch
EndFunc

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites

I think I tried every combination except possibly that one. Thanks Yoriz, I'll play with it to see what the outcome will be. I don't have to do multi-searches becuase if the string is found then the button is disabled and the string can't be entered into the Listview again. Therefore, only 1 occurance is allowed but it MUST be a full match, no partial matching allowed.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Just a little bit of adjustment and it works like a charm. Thank you very much, I was starting to get frustrated especially since the old library (PaulIA's) handled it with a single function.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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  
Followers 0