Share via


CComboBox::SetItemHeight

Call the SetItemHeight member function to set the height of list items in a combo box or the height of the edit-control (or static-text) portion of a combo box.

int SetItemHeight( 
   int nIndex, 
   UINT cyItemHeight  
);

Parameters

  • nIndex
    Specifies whether the height of list items or the height of the edit-control (or static-text) portion of the combo box is set.

    If the combo box has the CBS_OWNERDRAWVARIABLE style, nIndex specifies the zero-based index of the list item whose height is to be set; otherwise, nIndex must be 0 and the height of all list items will be set.

    If nIndex is –1, the height of the edit-control or static-text portion of the combo box is to be set.

  • cyItemHeight
    Specifies the height, in pixels, of the combo-box component identified by nIndex.

Return Value

CB_ERR if the index or height is invalid; otherwise 0.

Remarks

The height of the edit-control (or static-text) portion of the combo box is set independently of the height of the list items. An application must ensure that the height of the edit-control (or static-text) portion is not smaller than the height of a particular list-box item.

Example

// Set the height of every item to be the 
// vertical size of the item's text extent.
CString str;
CSize   sz;
CDC*    pDC = m_pComboBox->GetDC();
for (int i = 0; i < m_pComboBox->GetCount(); i++)
{
   m_pComboBox->GetLBText(i, str);
   sz = pDC->GetTextExtent(str);

   m_pComboBox->SetItemHeight(i, sz.cy);
}
m_pComboBox->ReleaseDC(pDC);

Requirements

Header: afxwin.h

See Also

Reference

CComboBox Class

Hierarchy Chart

CComboBox::GetItemHeight

WM_MEASUREITEM

CB_SETITEMHEIGHT