Moderators Melba23 Posted December 24, 2008 Moderators Share Posted December 24, 2008 (edited) Hi,I am running into a problem with ListView - I cannot get the highlight working correctly. The example code showing the problem (at least it does on my Vista32 machine) is here:expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <File.au3> #include <GUIListView.au3> #Include <GuiEdit.au3> Global $aArray[10] = ["1=Punc", "2=abc", "3=def", "4=ghi", "5=jkl", _ "6=mno", "7=pqrs", "8=tuv", "9=wxyz", "0=Space"] Global $iIndex = 0 $hMain_Window = GUICreate("List View Example", 240, 300, -1, -1) $hSearch_Input = GUICtrlCreateInput("", 15, 15, 90, 20) $hSearch_Button = GUICtrlCreateButton("Search", 125, 10, 80, 30, $BS_DEFPUSHBUTTON) $hList_View = GUICtrlCreateListView("Item1|Item2", 15, 50, 210, 245) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) GUICtrlSetBkColor(-1, 0xFF0000) _GUICtrlListView_SetColumnWidth(-1, 0, 90) _GUICtrlListView_SetColumnWidth(-1, 1, $LVSCW_AUTOSIZE_USEHEADER) _LV_Fill() GUISetState(@SW_SHOW, $hMain_Window) GUIRegisterMsg($WM_NOTIFY, "MY_WM_COMMAND") While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $hSearch_Button _Search() EndSwitch WEnd Func _Search() ;_GUICtrlListView_SetItemSelected($hList_View, $iIndex, False) $sTxt = GUICtrlRead($hSearch_Input) If $sTxt = "" Then Return $iIndex = _FindItem($hList_View, $sTxt, 0) If $iIndex = -1 Then MsgBox(0, "Search Error", "The element " & $sTxt & " does not exist.") Else _GUICtrlListView_SetItemSelected($hList_View, $iIndex) _GUICtrlListView_EnsureVisible($hList_View, $iIndex) EndIf EndFunc Func _LV_Fill() For $i = 0 To UBound($aArray) - 1 $aVar = _Split($aArray[$i], "=") GUICtrlCreateListViewItem($aVar[0] & "|" & $aVar[1], $hList_View) GUICtrlSetBkColor(-1, 0x00FF00) Next EndFunc Func _FindItem($hWnd, $2Find, $SubIndex) Local $iOut = -1 For $i = 0 To _GUICtrlListView_GetItemCount($hWnd) - 1 If _GUICtrlListView_GetItemText($hWnd, $i, $SubIndex) = $2Find Then $iOut = $i Next Return $iOut EndFunc Func _Split($sString, $sDelim) Local $aOut[2] Local $iLen = StringLen($sString) Local $iPos = StringInStr($sString, $sDelim, 1, 1) $aOut[0] = StringLeft($sString, $iPos - 1) $aOut[1] = StringRight($sString, $iLen - $iPos) Return $aOut EndFunc Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $tagNMHDR, $vEvent Switch $wParam Case $hList_View $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $vEvent = DllStructGetData($tagNMHDR, 3) Switch $vEvent Case $NM_CLICK GUICtrlSetData($hSearch_Input, _GUICtrlListView_GetItemText($hList_View, _GUICtrlListView_GetHotItem($hList_View), 0)) EndSwitch EndSwitch $tagNMHDR = 0 EndFunc Edited December 24, 2008 by Melba23 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...
Achilles Posted December 28, 2008 Share Posted December 28, 2008 GUICtrlSetState($hList_View, $GUI_FOCUS)? Put that in your search function... My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 28, 2008 Author Moderators Share Posted December 28, 2008 @Ichigo, Gracias. I just knew it was something simple! M23 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...
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