Based on ListCtrl Size Insert Rows

Posted on 2006-05-01
Last Modified: 2013-11-20
Basically what I would like to know is, if I know the vertical size of the list ctrl, I want to find out how many rows I can fit into the control before the scrollbar would appear.  Basically filling the ctrl but not 'over' filling.
Question by:cophi
    LVL 22

    Accepted Solution

    Have a look at CListCtrl::GetItemPosition() function. This function returns position of item in list control window as POINT.
    You may check this point against your window rect to verify Item is in window as you can then very well its  visible or not. <==

    BOOL GetItemPosition(   int nItem,   LPPOINT lpPoint ).


    POINT pt;

    UINT i, nCount = pmyListCtrl->GetItemCount();

    for (i=0;i < nCount;i++)
       pmyListCtrl->GetItemPosition(i, &pt);

    //check item is visible or not as you have window position


    LVL 22

    Expert Comment

    further you may use CRect::PtInRect() function to check point is in window rect or not. just pass point to function PtInRect of your list control's window rect.

    LVL 22

    Expert Comment

    Otherwise if you want to precalculate all.. you need to use functions like GetTextExtent / GetTextExtentPoint32 to calculate height of text string.. you may select list ctrl font on DC and then use above functions to calculate height of string in pixels then you may calculate total no of height of multiple items by adding all string items height. After that you may calculate how many rows will fit in list controls window rect.

    LVL 43

    Expert Comment

    This should be simpler to use

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    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…
    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.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 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

    6 Experts available now in Live!

    Get 1:1 Help Now