tags:

views:

170

answers:

2

I need to create a combo box in MFC /VC++ in which user can enter or select values in between 0 to 9999 only. How can I acheive this functionality.

Please Help

A: 

CComboBox* pCombo = (CComboBox*)GetDlgItem(IDS_COMBO1);

for (int i = 0; i < 9999; i++) pCombo->AddString(CString::Format(_T("%d"),i);

Kai
+2  A: 

Try this:

CComboBox* pCombo = (CComboBox*)GetDlgItem(IDC_COMBO1);

CWnd* pComboEdit = pCombo->GetWindow(GW_CHILD);

if (pComboEdit != NULL)
    pComboEdit->ModifyStyle(0, ES_NUMBER);


Edit: In order to restrict the number of characters/digits:

((CEdit*)pComboEdit)->LimitText(4);
Alan
its good. but i want to restrict to enter upto 4 character.i.e. 0 to 9999
Pankaj kumar
Perfect solution what I want. Thanks
Pankaj kumar
Then you might want to accept the answer ;)
Alan