You can use small arrays of int and CString to do this:
Code:
//------------------------------------------------------------------------------------------
// In the class header...
CArray <int, int> value;
CStringArray str_value;
CComboBox m_Combo1;
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
// In the class implementation....
//------------------------------------------------------------------------------------------
// in OnInitialUpdate() OR OnInitDialog()....
for (int i = 0; i < count /* number of elements in combo-box */; i++)
{
this->value.Add(0);
this->str_value.Add(_T(""));
}
// Set your values...if you did not while adding elements....
this->value.SetAt(0, number1);
this->value.SetAt(1, number2);
....
....
// Set the equivalent string values...
for(int k = 0; k < value.GetCount(); k++)
{
int num = this->value.GetAt(k);
str.Format(_T("%i"), num);
this->str_value.SetAt(k, str);
str.Empty();
}
// Or you can just set the numbers in the Add function as well...
// Fill up the combo-box...
int num = 0;
CString str;
for (int j = 0; j < count; j++)
{
// num = this->value.GetAt(j);
// str.Format(_T("%i"), num);
// Instead of the above two statements, use the following....
str = this->str_value.GetAt(j);
this->m_Combo1.AddString(str);
str.Empty();
}
//---------------------------------------------------------------------------------------------
// Handle the CBN_SELCHANGE event...
const int i = m_combo1.GetCurSel();
// CString str;
// m_combo1.GetLBText(value,str);
int value1 = this->str_value.GetAt(i);
//---------------------------------------------------------------------------------------------
// Now do what ever you want with value1.....
I hope that helps a bit. The idea is to sychronize the two separate arrays which helps eliminate the use of atoi() function.....and can be dealt with easily.
P.S.: My code may not be flawless. Regardless of that you would get a clue about how to approach your problem....
Regards,
Bhushan.