CComboBox::LimitText

BOOL LimitText( int nMaxChars );

Return Value

Nonzero if successful. If called for a combo box with the style CBS_DROPDOWNLIST or for a combo box without an edit control, the return value is CB_ERR.

Parameters

nMaxChars

Specifies the length (in bytes) of the text that the user can enter. If this parameter is 0, the text length is set to 65,535 bytes.

Remarks

Limits the length in bytes of the text that the user can enter into the edit control of a combo box.

If the combo box does not have the style CBS_AUTOHSCROLL, setting the text limit to be larger than the size of the edit control will have no effect.

LimitText only limits the text the user can enter. It has no effect on any text already in the edit control when the message is sent, nor does it affect the length of the text copied to the edit control when a string in the list box is selected.

Example

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

// Limit the number of characters in the combo box's edit control to
// be the maximum number visible.

// Get the text metrics for the combo box; needed for the
// average character width.
TEXTMETRIC tm;
CDC* pDC = pmyComboBox->GetDC();
pDC->GetTextMetrics(&tm);
pmyComboBox->ReleaseDC(pDC);

CRect r;
pmyComboBox->GetClientRect(&r);

pmyComboBox->LimitText(r.Width()/tm.tmAveCharWidth);

CComboBox OverviewClass MembersHierarchy Chart

See Also   CB_LIMITTEXT