Solved

How to trap ENTER Key press on a ListView control ?

Posted on 2001-08-13
10
1,601 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

627 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