Jump to content

ListView - search by key press (letter)


Recommended Posts

Hi everyone.
I have this question.
How to make ListView to respond to pressing a letter on the keyboard and select the list item that starts with that letter ?
I can't find a style that corresponds to such functionality.

For example:
I have a ListView that contains the names of employees of a company.
If I press the letter "a" on the keyboard, the ListView is supposed to highlight the first person whose name begins with the letter "a".

 

Thank you in advance for your help.

---edit---

In the example from the help it works properly.
In my program it does not work :(

This is my ListView definition:

$lvLista = GUICtrlCreatelistview("Lp|Imię i nazwisko|Telefon|Dział|Stanowisko|Przełożony|Firma",446,8,412,413,BitOr($LVS_SINGLESEL,$LVS_SHOWSELALWAYS),BitOr($LVS_EX_FULLROWSELECT,$LVS_EX_GRIDLINES,$WS_EX_CLIENTEDGE))

edit2

ok, I think I know.
I have the first column hidden and forgot about it myself ;)
It seems that this search works by default in the first column.
Now the question is how to change it ?
How to force ListView to search in the second column ?

Edited by Zmylna
Link to comment
Share on other sites

  • 2 weeks later...

try to get the data into an array and then use arraysearch to search the array

refer to code below (copied from @boludoz)

#include <StringConstants.au3>
#include <Array.au3>

Global $g_sString   = "Bob,24|Jane,25|Julian,26|"
Global $g_sDelimRow = '|'
Global $g_sDelimCol = ','

Global $g_aArray2D  = StringSplit2D($g_sString, $g_sDelimCol, $g_sDelimRow)
_ArrayDisplay($g_aArray2D, @ScriptName)

Func StringSplit2D($sMatches = "Hola-2-5-50-50-100-100|Hola-6-200-200-100-100", Const $sDelim_Item = "-", Const $sDelim_Row = "|", $bFixLast = Default)
    Local $iValDim_1, $iValDim_2 = 0, $iColCount

    ; Fix last item or row.
    If $bFixLast <> False Then
        Local $sTrim = StringRight($sMatches, 1)
        If $sTrim = $g_sDelimRow Or $sTrim = $sDelim_Item Then $sMatches = StringTrimRight($sMatches, 1)
    EndIf

    Local $aSplit_1 = StringSplit($sMatches, $sDelim_Row, $STR_NOCOUNT + $STR_ENTIRESPLIT)
    $iValDim_1 = UBound($aSplit_1, $UBOUND_ROWS)
    Local $aTmp[$iValDim_1][0], $aSplit_2
    For $i = 0 To $iValDim_1 - 1
        $aSplit_2 = StringSplit($aSplit_1[$i], $sDelim_Item, $STR_NOCOUNT + $STR_ENTIRESPLIT)
        $iColCount = UBound($aSplit_2)
        If $iColCount > $iValDim_2 Then
            $iValDim_2 = $iColCount
            ReDim $aTmp[$iValDim_1][$iValDim_2]
        EndIf
        For $j = 0 To $iColCount - 1
            $aTmp[$i][$j] = $aSplit_2[$j]
        Next
    Next
    Return $aTmp
EndFunc   ;==>StringSplit2D

for the keypress u can use the HotKeySet function

Edited by crackdonalds
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...