Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CListCtrl::GetTopIndex on KeyDown

Posted on 2004-10-19
13
Medium Priority
?
768 Views
Last Modified: 2013-11-20
Hi,
   I need to know the top index which is visible in the list control. For that I use CListCtrl::GetTopIndex().

But when I hook a function LVN_KEYDOWN for this list control. It always returns me 0. Basically I need to process something when the top index of the list control changes.

When the user uses mouse and scrollbar to scroll, GetTopIndex() works as expected. But on keydown or selection via mouse on a particular row it does not always return me the right TopIndex.

Note:
Observation made when I hit down arrow key GetTopIndex() returns me always 0. But when I hit up arrow key it returns me the right index.
0
Comment
Question by:akalmani
[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
  • 3
  • 3
  • 2
  • +3
13 Comments
 
LVL 6

Expert Comment

by:Amritpal Singh
ID: 12346073
have a look at the comment at the following link

http://www.geocities.com/codenit/tech/vc/control4/list28.htm
0
 
LVL 6

Expert Comment

by:Amritpal Singh
ID: 12346079
0
 
LVL 6

Expert Comment

by:Amritpal Singh
ID: 12346148
0
Independent Software Vendors: 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!

 
LVL 3

Author Comment

by:akalmani
ID: 12346184
amrit_82:
Did you read my question carefully?

I solved my question. Thanks for your suggestions. Infact I found a crook way to solve this issue.
0
 
LVL 3

Author Comment

by:akalmani
ID: 12346190
Does anyone know how to refund my points ??
0
 
LVL 13

Expert Comment

by:SteH
ID: 12346198
How do you get the CListCtrl pointer? Via the HWND contained in the message? If yes the function might return a temporary object.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12346210
>Does anyone know how to refund my points ??
You'd better read instructions carefully... http://www.experts-exchange.com/help.jsp#hi70
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12346216
Anyway, if you claim refund you need to post the solution
0
 
LVL 3

Author Comment

by:akalmani
ID: 12354844
SteH:
I have derived a class from CListCtrl. And I hooked LVN_KEYDOWN method to track keydown events. But when I call GetTopIndex() in this method I always get 0 for down arrow key. But I get the right value for up arrow key.

Anyways I resolved the question myself. I would not post the whole solution though here.

Override OnCustomDraw() and call GetTopIndex() in CDDS_ITEMPOSTPAINT.

VOID CMyListCtrl::OnCustomDraw(NMHDR *pHdr, LRESULT *pResult)
{
   LPNMLVCUSTOMDRAW lpvcd = (LPNMLVCUSTOMDRAW) pHdr;

   switch(lpvcd->nmcd.dwDrawStage)
   {
    case CDDS_PREPAINT:
             *pResult = CDRF_NOTIFYSUBITEMDRAW;
              break;
    case CDDS_ITEMPREPAINT:
             *pResult = CDRF_NOTIFYPOSTPAINT;
              break;
    case CDDS_ITEMPOSTPAINT:
           {
             int iIndex = GetTopIndex();            //This returns me the right value. Insert whatever logic here.
             *pResult = CDRF_DODEFAULT;
           }
              break;
   }
}
}
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 12356519
From link nonubik posted

Post a question in the Community Support topic area asking for a refund, and asking the Moderators to close the question. You'll be required to post your solution in your original question. A Moderator will post a notice of your request which will give the participants 96 hours to object to the refund. Note that if it resembles one of the suggested comments, the likelihood is that your request will not be granted, but rather, the points will be awarded to the Expert who makes the suggestion. In your Community Support request, remember to post a link to the original question.


Also you can delete
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21174988.html
yourself as long as no other expert posts a comment there.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12867816
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 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