Solved

listcontol selected item using keyboard

Posted on 2002-05-25
13
219 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 70
either24  challenge 19 97
pre4 challenge 19 100
unix example issues 18 90
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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