MilesAhead Posted August 20, 2009 Share Posted August 20, 2009 I can't seem to find how to detect when a ListBox gets the focus by tabbing into it. What's happening is I have an input line, when I press Tab the focus shifts to the ListBox but the top item isn't selected. This results in the user having to play around moving the arrow keys to get the first item selected. Ideally I'd like to know that the ListBox was entered due to Tabbing from the input line. Then I can just set the top item as selected. I don't want to interfere with mouse action so I only want to take non-default action if entry was from the input line and pressing Tab.. not via mouse click or backtab from another control. My Freeware Page Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 20, 2009 Moderators Share Posted August 20, 2009 MilesAhead, Take a look at this: #include <GUIConstantsEx.au3> #Include <GuiListBox.au3> #include <WinAPI.au3> $sData = "aaa|bbb|ccc" $hGUI = GUICreate("Test", 500, 500) $hInput = GUICtrlCreateInput("", 10, 10, 480, 20) $hListBox = GUICtrlCreateList("", 10, 50, 480, 300) GUICtrlSetData(-1 , $sData) GUISetState() $fListFocus = False $hLB_Handle = ControlGetHandle($hGUI, "", $hListBox) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch If _WinAPI_GetFocus() = $hLB_Handle And $fListFocus = False Then $iIndex = _GUICtrlListBox_GetTopIndex($hListBox) $sText = _GUICtrlListBox_GetText($hListBox, $iIndex) MsgBox(0, "Selected List Item", $sText) $fListFocus = True ElseIf _WinAPI_GetFocus() <> $hLB_Handle Then $fListFocus = False EndIf WEnd I think it does what you want. 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...
MilesAhead Posted August 20, 2009 Author Share Posted August 20, 2009 MilesAhead,Take a look at this:...Thanks for the reply. I had a WM_COMMAND handler already to catch mouse double click but it took me awhile to find the $LBN_SETFOCUS. Instead of worrying about the previous control in the Tab Stop chain, I just test if no items are selected when I get that notification. If none selected, set top item as selected. Seems to work pretty well. I can't believe I've been diddling with arrow keys for months instead of fixing it!!! Takes a jolt to unzombify my brain sometimes. Thanks for posting your code. I appreciate the help. >_< My Freeware Page 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