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
Solved

How to trap ENTER Key press on a ListView control ?

Posted on 2001-08-13
10
1,564 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Would like to move button in a function 3 79
Writing a parser for java language 4 83
show out valin of json for debugging in visaul c++ 1 41
Need some help with mailto 16 20
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

807 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