Solved

listcontol selected item using keyboard

Posted on 2002-05-25
13
216 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumNumber challenge 16 99
move a line in eclipse 3 60
java ^ examples 8 57
Path of Workbook 3 45
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

12 Experts available now in Live!

Get 1:1 Help Now