Link to home
Start Free TrialLog in
Avatar of manivannan
manivannan

asked on

How to trap ENTER Key press on a ListView control ?

How to trap ENTER Key press on a ListView control ?

LVN_KEYDOWN & NM_RETURN message handler are not getting triggered on pressing ENTER key.

Can anyone help me in solving this ?

[I am using a non-MFC appln. (ATL-SDK combination)]

Thanks.
Avatar of chandas
chandas

The guys on this forum can help you (They've helped me countless times) But please post some of your code so they can see what you're doing
Are you sure that the focus isn't on an edit box when you press the button?  An edit box is created for you to edit the contents of a cell in the ListView, and is a child control of the ListView.  You could try tabbing to the control in question and pressing ENTER when no edit box is present.

If you're trying to process the info in the edit box by handling the ENTER key, you should use LVN_ITEMCHANGING instead.
Avatar of manivannan

ASKER

> Are you sure that the focus isn't on an edit box when you press the button?

My answer: Yes, I have disabled 'EDIT' option. Also, I am able to trap key down of all the alphanumeric keys.

Please suggest.

Thanks.
This is the portion of my code
--------------------------------

// CDialogClass

#include "resource.h"
#include <atlhost.h>

class CDialogClass :
{
public:
     enum { IDD = IDD_DIALOG1 };

BEGIN_MSG_MAP(CDialogClass)
     NOTIFY_HANDLER(IDC__LIST_PRODUCTS, LVN_KEYDOWN, OnKeyDown_list_products)
END_MSG_MAP()

private:
public:
     LRESULT OnKeyDown_list_products(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
     {
          UNUSED_ALWAYS(idCtrl);

          LPNMLVKEYDOWN pnkd;

          HRESULT hr=S_OK;
          bHandled = true;
          pnkd = (LPNMLVKEYDOWN) pnmh;

          if (pnkd->wVKey != VK_RETURN)
               return 0;

          hr = DoMyProcessing();
          if (FAILED(hr))
               return hr;

          return 0;
     }

};

Avatar of Axter
Is this an MFC application?
Does this *exact* code, with VK_RETURN replaced with, say VK_ESCAPE work?

Also (might be silly, but...) did you try VK_ENTER?
Oops. I could have sworn that VK_ENTER was defined separately.
I tryed just now with LV and observed the problem. When
a parent window starts and loads items to LV keyboard
focus directed to parent of LV window, so i can receive
from parent window message queue WM_CHAR and WM_KEYDOWN.
After mouse click to LV window keyboard messages goes
somewere to Commctrl.dll maybe. Seem's it posible to retrive it, let me try filter (MDI) application messages
later (somewere around GetMessage ()...).
Alex.
Must be a some MFC trick you have, manivannan. In win32api application the code below working correctly.
// this is message dispaching of host of LV window:
case WM_NOTIFY:
 {//1
  int idFrom  = (int)wParam;
  NMHDR *pnmhdr  = (NMHDR *)lParam;
  if(idFrom== 0)
  {if(pnmhdr->code==HDN_ENDTRACK)
   PostMessage(hwndHostLVin,WM_COMMAND,ID_COL_WIDTH_CHANGED,0);
 return DefMDIChildProc(hwndHostLVin, uiMessage, wParam,lParam);
  }
  switch (pnmhdr->code)
  {//2
   // in this place lot of LVN_ other cases (not included)
   case LVN_KEYDOWN :  
   { LV_KEYDOWN *pnmkd=(LV_KEYDOWN*)lParam;
    if(pnmkd->wVKey==VK_RETURN)Mbox("VK_RETURN received");
   }
   break;
     
  }//2
 }//1
break;
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and PAQ at zero points since nobody had an answer for you.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial