Click to See Complete Forum and Search --> : CDialog & CComboBox init


panza
June 11th, 1999, 12:27 PM
Let's say I've got a OnLClick(...) in which I want to popup a dialog (created with the resource-editor)
and before doing a DoModal(); I want to set the CComboBox, which is a control of the dialog, to a
specific value... but it keeps crashing at SetCurSel:

CTestDlg *dlg=new CTestDlg(this);
dlg->m_combo.SetCurSel(0);
dlg->DoModal();

m_combo is a member-variable (control) of the dialog. I've also tried to get the control:

CTestDlg *dlg=new CTestDlg(this);
CComboBox *cb=(CComboBox *)dlg->GetDlgItem(IDC_COMBO1);

But here, the GetDlgItem crashes... I feel that I'm doing something completely wrong, but
I have no clue... could anybody please help me?

Thank you!


-.-.-

ChrisD
June 11th, 1999, 02:46 PM
Create a memeber variable in your dialog class and set it to the selection you want, then in OninitDialog call SetCurSel. You are calling SetCurSel before DoModal which means the physical dialog does not exist yet, resulting in a crash.

HTH,
Chris

panza
June 11th, 1999, 05:05 PM
How come I can set any other CEdit-controls of this dialog, heck, I can even set the VALUE
of the CComboBox (if I use a value-member-variable instead of a control-variable for the
CComboBox) to any value I want and it doesn't crash (but I want to use an item added via
resource-editor).

Is it because the items of this box aren't existing before calling DoModal(), but the ComboBox
itself exists? Don't ask, but I don't want to use OnInitDialog for some reason. I want to set the
initial value of CComboBox (which has items added via resource-editor!) in the function, which
creates the dialog and does the DoModal()... any chance?

Thanks!


-.-.-