Solved

Working with two dialogs.

Posted on 2000-04-10
3
189 Views
Last Modified: 2013-11-20
Hallo,

I have two dialogs. Lets call them Dialog1 and Dialog2.
The main dialog is Dialog1, and Dialog2 pops up when I click somewhere
in Dialog1.
In Dialog2 I have a Combobox, and I get the problem (Assertion Failure) when
I try to retrieve the information of this combobox from Dialog1, with a sentence
like this:
      int PMODEPADsel = dlg.m_CDecTypeOfTheNewSC.GetCurSel();
//m_CDecTypeOfTheNewSC is the variable associated to the combobox.

Well, the whole code of this part is:

if(dlg.DoModal() == IDOK)
{
      if (dlg.m_NameOfTheNewSC!=""){
            SetAllRelatedToSC(true);
            ActualEnsemble->ListOfSC[num].SC_Label=dlg.m_NameOfTheNewSC;
            ActualEnsemble->ListOfSC[num].String1=dlg.m_CDecChAdrOfTheNewSC;
            ActualEnsemble->ListOfSC[num].String2=dlg.m_CDecChIdOfTheNewSC;
//Here is where I get the problem!!:
            int PMODEPADsel = dlg.m_CDecTypeOfTheNewSC.GetCurSel();
            if (PMODEPADsel==0){  //PAD selected
                  m_PMODEPAD.SetCurSel(0);
            }
            if (PMODEPADsel==1){  //PMODE selected
                  m_PMODEPAD.SetCurSel(1);
            }
      }
}
0
Comment
Question by:javigil1
3 Comments
 
LVL 2

Expert Comment

by:paulburns
ID: 2702457
You can't use any member functions of  control's once the dialog has been dismissed. All those controls in the dialog have been destroyed at that point and although you may still have a CComboBox object around its no longer attached to an *actual* combo box.

Use DDX to save the user's selection from the combo to a member variable.
0
 
LVL 1

Accepted Solution

by:
jianliuer earned 75 total points
ID: 2702720
When the modal dialog is closed(click the OK button),all controls in the dialog are destroyed(the combobox is destroyed).So you should save the selection state in the virtual function CDialog::OnOK();

You can do like this:

m_PMODEPADsel is a member variable of your CXXXDialog class.

CXXXDialog::OnOK()
{
 UpdateData();
 m_PMODEPADsel =  m_CDecTypeOfTheNewSC.GetCurSel();
//////////////////////
 CDialog::OnOK();
}


if(dlg.DoModal() == IDOK)
{
if (dlg.m_NameOfTheNewSC!=""){
SetAllRelatedToSC(true);
ActualEnsemble->ListOfSC[num].SC_Label=dlg.m_NameOfTheNewSC;
ActualEnsemble->ListOfSC[num].String1=dlg.m_CDecChAdrOfTheNewSC;
ActualEnsemble->ListOfSC[num].String2=dlg.m_CDecChIdOfTheNewSC;

//Here it is!
int PMODEPADsel = dlg.m_PMODEPADsel;

if (PMODEPADsel==0){  //PAD selected
m_PMODEPAD.SetCurSel(0);
}
if (PMODEPADsel==1){  //PMODE selected
m_PMODEPAD.SetCurSel(1);
}
}
}
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2703500
What you can do is that you can have an array/list member in dialog1 for storing all the items in the combobox and an integer to store the current selection.
Fill up the array/list in Dialog2 with the items in the combobox and set the current selection. Now when the 2nd dialog is closed, you can still access the selected position and the item in that position.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now