Solved

Working with two dialogs.

Posted on 2000-04-10
3
201 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand macro to include alternate header placement and naming 5 65
Question regarding Copy/Paste 16 91
format the code in java 6 85
sum67 challenge 35 93
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

947 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