Jump to content

ListView Subitem Partial Search from start of string


PaulSt
 Share

Recommended Posts

_GUICtrlListView_FindItem() does a partial search from the start of the string in the item (col 1).

ControlListView() does a complete match (but not partial) in any subitem.

_GUICtrlListView_FindInText() matches any text in any item/subitem.

Has anyone devised an implementation that does a partial search from the start of the string in a subitem (i.e. col2)?

Link to comment
Share on other sites

You can open the GuiListView.au3 UDF, copy out the _GUICtrlListView_FindInText() function and tweak it any way you need. All it's doing is StringInStr() compares in nested loops. You can modify the loop to get only the col you want, and exactly the compare you need.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You can open the GuiListView.au3 UDF, copy out the _GUICtrlListView_FindInText() function and tweak it any way you need. All it's doing is StringInStr() compares in nested loops. You can modify the loop to get only the col you want, and exactly the compare you need.

;)

Many Thanks PsaltyDS. I should have thought of that. It shows why you are an MVP and I'm just a newbie.

I have a combobox to select the col name. I parse out the col name to get the col, then I search for the text in that col, and limit the len of the text to be searched to the len of the search text (for partial to work). Works great:

Local $iCol, $sList

If $iColumn = False Then

Local $c = GUICtrlRead($hComboFindCol) & "|"

Local $c1 = $sListViewColHdrs & "|"

Local $i = StringInStr($c1, $c)

Local $c2 = StringLeft($c1, $i)

Local $a = StringSplit($c2, "|")

$iCol = $a[0] - 1

Else

$iCol = $iColumn - 1

EndIf

Local $sText = GUICtrlRead($hInputFindItem)

Local $iLen = StringLen($sText)

;MsgBox(0,0,$iLen)

Local $iCount = _GUICtrlListView_GetItemCount($hListView)

;MsgBox(0, 0, $iCount)

For $iI = 0 To $iCount - 1

$sList = _GUICtrlListView_GetItemText($hListView, $iI, $iCol)

;MsgBox(0,0,$sList)

If StringInStr(StringLeft($sList,$iLen), $sText) Then

_GUICtrlListView_ClickItem($hListView, $iI)

ExitLoop

EndIf

Next

Link to comment
Share on other sites

Glad it helped. :)

I notice one minor issue, depending on you use this. You test "If $iCol = False", presumably to see if you have the col number yet, and the first thing I think is that 0 is a valid col number and 0 = False is true in AutoIt. You might initialize $iCol to -1 and then test "If $iCol >= 0" to verify you have a column number. That might not even be an issue depending on how you are using that.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Glad it helped. :)

I notice one minor issue, depending on you use this. You test "If $iCol = False", presumably to see if you have the col number yet, and the first thing I think is that 0 is a valid col number and 0 = False is true in AutoIt. You might initialize $iCol to -1 and then test "If $iCol >= 0" to verify you have a column number. That might not even be an issue depending on how you are using that.

;)

I have considered that and thanks for bringing it up and more importantly, your interest.
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...