Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

Based on ListCtrl Size Insert Rows

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.
0
cophi
Asked:
cophi
  • 3
1 Solution
 
mahesh1402Commented:
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.

http://msdn2.microsoft.com/en-US/library/t32w446y(VS.80).aspx <==

BOOL GetItemPosition(   int nItem,   LPPOINT lpPoint ).

e.g

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
  ....

}

-MAHESH
0
 
mahesh1402Commented:
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.

-MAHESH
0
 
mahesh1402Commented:
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.

-MAHESH
0
 
AndyAinscowCommented:
This should be simpler to use
CListCtrl::GetCountPerPage
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now