ajit Posted September 3, 2009 Share Posted September 3, 2009 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 3, 2009 Moderators Share Posted September 3, 2009 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.expandcollapse popup#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 ;==>KeywordsI had this ready coded from another topic - I hope it helps.M23P.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). Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ajit Posted September 3, 2009 Author Share Posted September 3, 2009 @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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now