PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: jcmatt on March 04, 2009, 10:54:55 AM

Title: Where does the listbox Enter Key event go
Post by: jcmatt on March 04, 2009, 10:54:55 AM
Hi,

There doesn't seem to be any Key events for the listbox control.
Where/how do I detect the Enter key being pressed to select an item in a listbox?

Jim
Title: Re: Where does the listbox Enter Key event go
Post by: Pat Dooley on March 04, 2009, 04:52:25 PM
Someone may have a better approach, but this seems to work in the listbox custom event.
Function FORM1_LIST1_CUSTOM ( _
                            ControlIndex  As Long,  _  ' index in Control Array
                            hWndForm      As Dword, _  ' handle of Form
                            hWndControl   As Dword, _  ' handle of Control
                            wMsg          As Long,  _  ' type of message
                            wParam        As Dword, _  ' first message parameter
                            lParam        As Long   _  ' second message parameter
                            ) As Long

Local mystr As String
Local idx As Long

If wParam = %VK_RETURN Then  '%WM_CHAR Then
      'now do something such as...
      idx=FF_ListBox_GetCurSel (HWND_FORM1_LIST1)
      mystr=FF_ListBox_GetText (HWND_FORM1_LIST1, idx)
      FF_TextBox_SetText (HWND_FORM1_TEXT1, mystr)
End If

End Function

Good luck.

Pat
Title: Re: Where does the listbox Enter Key event go
Post by: jcmatt on March 04, 2009, 05:52:55 PM
Thanks Pat, works great.

Jim
Title: Re: Where does the listbox Enter Key event go
Post by: TechSupport on March 04, 2009, 06:03:28 PM
Hi Guys,

Pat, be careful with your approach because you are not filtering out the messages in your CUSTOM message handler. Try the code below (you need the WM_GETDLGCODE to ensure that the keypresses are handled by the ListBox).


Function FORM1_LIST1_CUSTOM ( _
                            ControlIndex  As Long,  _  ' index in Control Array
                            hWndForm      As Dword, _  ' handle of Form
                            hWndControl   As Dword, _  ' handle of Control
                            wMsg          As Long,  _  ' type of message
                            wParam        As Dword, _  ' first message parameter
                            lParam        As Long   _  ' second message parameter
                            ) As Long

   Select Case wMsg

      Case %WM_GETDLGCODE
         Function = %DLGC_WANTALLKEYS
         Exit Function
     
      Case %WM_CHAR
         If wParam = %VK_RETURN Then 
            MsgBox "ENTER key pressed"
         End If

   End Select
   
End Function


Title: Re: Where does the listbox Enter Key event go
Post by: jcmatt on March 05, 2009, 01:18:42 PM
Thanks Paul, Jim
Title: Re: Where does the listbox Enter Key event go
Post by: Pat Dooley on March 06, 2009, 10:48:53 AM
Thanks Paul for fixing my code. While it seemed to work OK, I thought that it seemed a little simplistic. When it comes to handling Windows messages, I feel like the guy trying to find a black cat in a coal bin at midnight.
Title: Re: Where does the listbox Enter Key event go
Post by: TechSupport on March 06, 2009, 12:06:04 PM
No problem Pat - happy to help.  :)