Question

I have the following

void AggiungiEsameDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBO1, ComboBoxVoti);
CString a;
for (int i = 18; i <= 30; i++)
{
    a.Format(_T("%d"), i);
    ComboBoxVoti.AddString(a);
}


DDX_Text(pDX, IDC_EDIT1,nome);

DDX_CBIndex(pDX, IDC_COMBO1, voto);

}

with ComboBoxVoti of type CComboBox and member of class.

if I call ComboBoxVoti.GetCurSel I have the exact index( 0 for 18, 1 for 19 and so on) but in voto (linked by DDX_CBIndex) I have 1 for 18, 3 for 19, 5 for 20, 7 for 21 and so on!! why?

Was it helpful?

Solution

As Igor wrote, you should never add the items on every call to OnInitDialog.

You can protect this with an ** if (!pDX->m_bSaveAndValidate) **.

And you should clear the Combobox before you insert items into it, to reset it to an unique initial state.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top