Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining


Call the GetItemHeight member function to retrieve the height of list items in a combo box.

int GetItemHeight(
   int nIndex 
) const;



Specifies the component of the combo box whose height is to be retrieved. If the nIndex parameter is –1, the height of the edit-control (or static-text) portion of the combo box is retrieved. If the combo box has the CBS_OWNERDRAWVARIABLE style, nIndex specifies the zero-based index of the list item whose height is to be retrieved. Otherwise, nIndex should be set to 0.

The height, in pixels, of the specified item in a combo box. The return value is CB_ERR if an error occurs.

// The pointer to my combo box.
extern CComboBox* pmyComboBox;

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

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

Community Additions

© 2015 Microsoft