Sign in to follow this  
Followers 0
ajit

Listview difficulty

3 posts in this topic

Hi

I have a listview with an input for search (Find).

I want the listview to scroll and select item (as I type) when it finds an appropriate match in search input box.

_GUICtrlListView_GetISearchString($listview) searches it when focus is on the listview but I need focus on input (Find).

I am not getting a clue on how to go about it.

Please help me out.

Thanks in anticipation.

Ajit

The code herebelow:

#include <GuiConstantsEx.au3>

#include <GuiListView.au3>

#include <WindowsConstants.au3>

#include <array.au3>

Global $listview, $Row_Changed

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

$main = GUICreate("Find n Replace", 500, 190)

$listview = GUICtrlCreateListView("Find|Replace", 10, 60, 480, 100)

GUICtrlSendMsg(-1, 0x101E, 0, 250)

GUICtrlSendMsg(-1, 0x101E, 1, 250)

$item0 = GUICtrlCreateListViewItem("She's|She is", $listview)

$item1 = GUICtrlCreateListViewItem("He's|He is", $listview)

$item2 = GUICtrlCreateListViewItem("patien |patient", $listview)

$item3 = GUICtrlCreateListViewItem("surger|surgery", $listview)

$item4 = GUICtrlCreateListViewItem("year old|-year-old", $listview)

$item5 = GUICtrlCreateListViewItem("Vicodyn|Vicodin", $listview)

$listview = GUICtrlGetHandle($listview)

GUICtrlCreateLabel("Find:", 10, 7, 25, 16)

GUICtrlCreateLabel("Replace:", 10, 32, 45, 16)

$Label_Row = GUICtrlCreateInput("", 60, 5, 630, 20)

$Label_Row2 = GUICtrlCreateInput("", 60, 30, 630, 20)

GUISetState()

_GUICtrlListView_RegisterSortCallBack($listview)

_GUICtrlListView_SortItems($listview, 0)

_GUICtrlListView_GetISearchString($listview)

While 1

$msg = GUIGetMsg()

Switch $msg

Case $GUI_EVENT_CLOSE

Exitloop

EndSwitch

If $Row_Changed Then

;GUICtrlSetData($Label_Row,_GUICtrlListView_GetSelectionMark($listview))

$index = _GUICtrlListView_GetSelectionMark($listview)

$dat = _GUICtrlListView_GetItemText($listview, $index)

$dat2 = _GUICtrlListView_GetItemText($listview, $index, 1)

GUICtrlSetData($Label_Row, $dat )

GUICtrlSetData($Label_Row2, $dat2 )

$Row_Changed = 0

EndIf

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

#forceref $hWnd, $iMsg, $iwParam

$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)

$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))

$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")

$iCode = DllStructGetData($tNMHDR, "Code")

Switch $hWndFrom

Case $listview

Switch $iCode

Case -155

$Row_Changed = 1

Case $NM_CLICK

$Row_Changed = 1

EndSwitch

EndSwitch

Return $GUI_RUNDEFMSG

EndFunc

Share this post


Link to post
Share on other sites



ajit,

This is not quite what you said you wanted, but perhaps you might find it interesting as it is not too different. The listbox will fill with matching strings as you begin typing in the input box. Clicking a string in the list puts it into the input box directly.

#include <GUIConstantsEx.au3>

Global $INPUT, $LIST, $LIST_DATA = "", $KEYWORD[100], $NEW_DATA = "|"

$MAIN = GUICreate("Example", 200, 150)
$INPUT = GUICtrlCreateInput("", 5, 5, 190, 20)
$LIST = GUICtrlCreateList("", 5, 30, 190, 60, BitOR(0x00100000, 0x00200000))
GUICtrlSetState(-1, $GUI_HIDE)

; create list of random 5 letter groups
Keywords()

GUISetState(@SW_SHOW, $MAIN)

$sCurr_Input = ""

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $LIST
            $sChosen = GUICtrlRead($LIST)
            If $sChosen <> "" Then GUICtrlSetData($INPUT, $sChosen)
    EndSwitch

    ; Show/hide list depending on input content and list data
    If GUICtrlRead($INPUT) <> "" And BitAND(GUICtrlGetState($LIST), $GUI_HIDE) = $GUI_HIDE And $NEW_DATA <> "|" Then GUICtrlSetState($LIST, $GUI_SHOW)
    If GUICtrlRead($INPUT) = "" And BitAND(GUICtrlGetState($LIST), $GUI_SHOW) = $GUI_SHOW Then GUICtrlSetState($LIST, $GUI_HIDE)

    ; If input has changed, refill list with matching items
    If GUICtrlRead($INPUT) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($INPUT)
    EndIf

WEnd

Func CheckInputText()
    $l = StringLen(GUICtrlRead($INPUT))
    $NEW_DATA = "|" ; Start with delimiter so new data always replaces aold
    $READ = GUICtrlRead($INPUT)
    If $READ <> "" Then
        For $INDEX = 0 To 99
            If StringLeft($KEYWORD[$INDEX], $l) = $READ Then $NEW_DATA &= $KEYWORD[$INDEX] & "|"
        Next
        GUICtrlSetData($LIST, $NEW_DATA)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()
    For $INDEX = 0 To 99
        $KEYWORD[$INDEX] = Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1))
        $LIST_DATA &= $KEYWORD[$INDEX] & "|"
    Next
    GUICtrlSetData($LIST, $LIST_DATA)
EndFunc   ;==>Keywords

I had this ready coded from another topic - I hope it helps.

M23

P.S. Please use Code tags. Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here). :D


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

@Melba23

Hi,

Thanks a lot for your help. It is very close to what I needed. I will try to modify to use in my code.

Thanks again.

Regards,

Ajit

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