Solved

listcontol selected item using keyboard

Posted on 2002-05-25
13
218 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

920 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

16 Experts available now in Live!

Get 1:1 Help Now