Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

listcontol selected item using keyboard

Posted on 2002-05-25
13
Medium Priority
?
255 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
[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
  • 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 600 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Technology Partners: 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!

Question has a verified solution.

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

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…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

704 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