Share via


CListBox::GetItemHeight

intGetItemHeight(intnIndex**)const;**

Return Value

The height, in pixels, of the items in the list box. If the list box has the LBS_OWNERDRAWVARIABLE style, the return value is the height of the item specified by nIndex. If an error occurs, the return value is LB_ERR.

Parameters

nIndex

Specifies the zero-based index of the item in the list box. This parameter is used only if the list box has the LBS_OWNERDRAWVARIABLE style; otherwise, it should be set to 0.

Remarks

An application calls the GetItemHeight member function to determine the height of items in a list box.

Example

// The pointer to my list box.
extern CListBox* pmyListBox;

// Set the height of every item so the item
// is completely visible.
CString str;
CSize   sz;
int     dx=0;
CDC*    pDC = pmyListBox->GetDC();
for (int i=0;i < pmyListBox->GetCount();i++)
{
   pmyListBox->GetText( i, str );
   sz = pDC->GetTextExtent(str);

   // Only want to set the item height if the current height
   // is not big enough.
   if (pmyListBox->GetItemHeight(i) < sz.cy)
      pmyListBox->SetItemHeight( i, sz.cy );
}
pmyListBox->ReleaseDC(pDC);

CListBox OverviewClass MembersHierarchy Chart

See Also   , CListBox::SetItemHeight