Solved

CListCtrl::GetTopIndex on KeyDown

Posted on 2004-10-19
13
743 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 44

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 83
WinWaitActive parameters 12 31
abstract class with all non abstract mentods 6 72
mapAB Challlenge 35 88
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

758 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

19 Experts available now in Live!

Get 1:1 Help Now