Solved

listcontol selected item using keyboard

Posted on 2002-05-25
13
220 Views
Last Modified: 2013-11-20
hi,

when i am click on an item in my listcontrol (reportview)
using the mouse i can get the info of this item using:

POSITION pos=m_MenuList.GetFirstSelectedItemPosition();
int nItem=m_MenuList.GetNextSelectedItem(pos);

how i can find the index of the item while scrolling using the up/down arrows?
it always give me the previous index and not the selected one?
thanks
0
Comment
Question by:talsp
  • 6
  • 5
  • 2
13 Comments
 

Expert Comment

by:plamtod
ID: 7034543
Try to subclass listctr(derive your class from it and from OnInitDlg or InitialUpdate call SubclassDlgItem for instance of this class)
and in PreTranslateMessage() of this class
{
if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_UP)
CPoint point;
GetCursorPos(&point);
if(-1 != HitTest(point))
index = HitTest(point);
}
0
 
LVL 12

Accepted Solution

by:
migel earned 150 total points
ID: 7034618
Hi!
you have to catch LVN_ITEMCHANGED notify message and check
uNewState member of the LPNMLISTVIEW for LVIS_SELECTED flag
that is

//////////////////
// User selected a different item: select the form
//
LRESULT CLeftView::OnItemChanged(NMLISTVIEW* pnmlv)
{
   if ((pnmlv->uChanged & LVIF_STATE) &&
       (pnmlv->uNewState & LVIS_SELECTED)) {
       m_pFormView->SetForm(pnmlv->iItem);
   }
   return 0;
}
0
 

Author Comment

by:talsp
ID: 7034643
i didnt understand both of you.
can u please explain me more?

0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 12

Expert Comment

by:migel
ID: 7035040
you must insert notify handler into the ListView Parent window. or use MFC message reflection to catch it in the listview object(to do this you must derive your own class from standard CListViewCtrl)
0
 

Author Comment

by:talsp
ID: 7035068
migel: i try both your options but they dont seem to work
there seems to be now SetForm Function
and the parameters to OnLvnItemchangedMenulist are (NMHDR *pNMHDR, LRESULT *pResult)
0
 
LVL 12

Expert Comment

by:migel
ID: 7035167
so
LRESULT CLeftView:: OnLvnItemchangedMenulist(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pnmlv = (LPNMLISTVIEW)pNMHDR;
  if ((pnmlv->uChanged & LVIF_STATE) &&
      (pnmlv->uNewState & LVIS_SELECTED)) {
// pnmlv->iItem - selected item
  }
  return 0;
}
0
 

Expert Comment

by:plamtod
ID: 7035184
if you make your class CMyList:public CListCtrl and on call in CYouDlg::OnInitDlg{ mylist.SubclassDlgItem(IDC_LISTCTRL)}
where mylist is instance of your class(CMyList), all messages will handled by your class(WM_LBUTTONDOWN and so on). if you try code in PreTranslateMessage above to filter msg I think it should work.
0
 

Author Comment

by:talsp
ID: 7035196
migel: its still doesnt work.

plamtod: it doesnt recognize both index and HitTest.
0
 
LVL 12

Expert Comment

by:migel
ID: 7035652
hmm
show your code or do you want simple example application?
0
 

Author Comment

by:talsp
ID: 7035655
an example would be great
0
 
LVL 12

Expert Comment

by:migel
ID: 7036624
your eMail?
0
 

Author Comment

by:talsp
ID: 7036802
talsp@msn.com
0
 

Author Comment

by:talsp
ID: 7037443
Thanks, really appreciate it.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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
How to create frequencies of a variable from SAS dataset? 10 133
conditional code and condition difference 9 84
Doc'in system (example?) BA 7 115
Message not shown 5 67
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

828 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