CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    16

    CDialog & CComboBox init

    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!


    -.-.-

  2. #2
    Join Date
    May 1999
    Posts
    667

    Re: CDialog & CComboBox init

    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


  3. #3
    Join Date
    May 1999
    Posts
    16

    Re: CDialog & CComboBox init

    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!


    -.-.-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured