Solved

How to trap ENTER Key press on a ListView control ?

Posted on 2001-08-13
10
1,525 Views
Last Modified: 2012-06-21
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.
0
Comment
Question by:manivannan
10 Comments
 

Expert Comment

by:chandas
ID: 6379476
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
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6379517
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.
0
 

Author Comment

by:manivannan
ID: 6379991
> 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;
     }

};

0
 
LVL 30

Expert Comment

by:Axter
ID: 6380240
Is this an MFC application?
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6380391
Does this *exact* code, with VK_RETURN replaced with, say VK_ESCAPE work?

Also (might be silly, but...) did you try VK_ENTER?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 4

Expert Comment

by:IainHere
ID: 6380569
Oops. I could have sworn that VK_ENTER was defined separately.
0
 
LVL 1

Expert Comment

by:ua1zcl
ID: 6381202
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.
0
 
LVL 1

Expert Comment

by:ua1zcl
ID: 6381329
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;
0
 
LVL 11

Expert Comment

by:griessh
ID: 6851211
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
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 6874968
Per recommendation points refunded and question closed.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now