Solved

How to trap ENTER Key press on a ListView control ?

Posted on 2001-08-13
10
1,579 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

696 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