Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How do I handle "enter" key in a listbox?

How do I handle "enter" key in a listbox?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fferland
    wrote on last edited by
    #1

    I have a dialog with two listboxes in it. I want my listboxes to do something when the "enter" key is pressed. The LBN_* messages listed in the ClassWizard are of no help. I tried responding to WM_KEYUP/DOWN messages from the parent dialog, but the didn't work either. How can I know when the user hits "enter" from a listbox?

    J T A 3 Replies Last reply
    0
    • F fferland

      I have a dialog with two listboxes in it. I want my listboxes to do something when the "enter" key is pressed. The LBN_* messages listed in the ClassWizard are of no help. I tried responding to WM_KEYUP/DOWN messages from the parent dialog, but the didn't work either. How can I know when the user hits "enter" from a listbox?

      J Offline
      J Offline
      James Pullicino
      wrote on last edited by
      #2

      Try handling OnKeyDown (sorry, I forgot the actual message define) Drinking In The Sun Forgot Password?

      1 Reply Last reply
      0
      • F fferland

        I have a dialog with two listboxes in it. I want my listboxes to do something when the "enter" key is pressed. The LBN_* messages listed in the ClassWizard are of no help. I tried responding to WM_KEYUP/DOWN messages from the parent dialog, but the didn't work either. How can I know when the user hits "enter" from a listbox?

        A Offline
        A Offline
        Alwin75
        wrote on last edited by
        #3

        Hi there, I respond to "del" keys in my listviews by handling the KEYDOWN notifications, this solution should also work for listboxes: In your message map add: (you should use LBN_*) ON_NOTIFY(LVN_KEYDOWN, IDC_LIST_FILES, OnKeydownListFiles) Add the handler: void CUpdateDlg::OnKeydownListFiles(NMHDR* pNMHDR, LRESULT* pResult) { LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR; if (pLVKeyDow->wVKey == 46) { // Delete key pressed } *pResult = 0; } Hope this helps ! Alwin

        1 Reply Last reply
        0
        • F fferland

          I have a dialog with two listboxes in it. I want my listboxes to do something when the "enter" key is pressed. The LBN_* messages listed in the ClassWizard are of no help. I tried responding to WM_KEYUP/DOWN messages from the parent dialog, but the didn't work either. How can I know when the user hits "enter" from a listbox?

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          Override CYourDlg::PreTranslateMessage, check if listbox has the focus and key is Enter, then do whatever you want. Tomasz Sowinski -- http://www.shooltz.com

          To some its a six-pack, to me it's a support group

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups