Solved

CListCtrl::GetTopIndex on KeyDown

Posted on 2004-10-19
13
744 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 48
Question regarding Copy/Paste 16 91
Include multiple hostnames in this command? 3 53
Problem to event 3 76
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: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 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

17 Experts available now in Live!

Get 1:1 Help Now