Solved

Combo Box in Modeless dialog: Run-time error

Posted on 2004-09-07
4
239 Views
Last Modified: 2013-11-20
hi all,

    I used Combo Box(m_VCDsearchChoose) in Modeless dialog (class DlgVCDSearch)

    While running DlgSearch.m_VCDsearchChoose.AddString("Area"); and int sel = DlgSearch.m_VCDsearchChoose.GetCurSel(); gives Run-time error.


void CMovieCollectorView::OnSearchVcd()
{
      // TODO: Add your command handler code here
                . . .
      DlgVCDSearch DlgSearch;
      DlgSearch.m_VCDsearchChoose.AddString("Area");
      if(DlgSearch.DoModal() == IDOK)
      {
            int sel = DlgSearch.m_VCDsearchChoose.GetCurSel();
                                . . .            
      }
}

   Please let me know how to overcome this problem

   with warm regards
   -Mahesh
0
Comment
Question by:smpoojary
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 125 total points
ID: 12003808
This is a MODAL dialog, not a modeless.

At the time you use
int sel = DlgSearch.m_VCDsearchChoose.GetCurSel();
the dialog window (and its children) is destroyed hence you get the error.

You need to use the OnOK of the dialog to set a public member var of the dialog to that value and access that var.

eg.
In DlgVCDSearch::OnOK
m_iSel = m_VCDsearchChoose.GetCurSel();

and in your other code
void CMovieCollectorView::OnSearchVcd()
{
     // TODO: Add your command handler code here
                . . .
     DlgVCDSearch DlgSearch;
     DlgSearch.m_VCDsearchChoose.AddString("Area");
     if(DlgSearch.DoModal() == IDOK)
     {
          int sel = DlgSearch.m_iSel;
                                . . .          
     }
}
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 12003933
This line will not work also:

DlgSearch.m_VCDsearchChoose.AddString("Area");

This should be done in OnInitDialog.
0
 
LVL 4

Author Comment

by:smpoojary
ID: 12013033
hi,

    Thanks for AndyAinscow and AlexFM.

    I don't know to whom I have to give points. Both are telling correct. Now I will select AndyAinscow for quick response. Again thanks for AndyAinscow and AlexFM.

    With warm regards.
   -Mahesh
0
 
LVL 4

Author Comment

by:smpoojary
ID: 12187456
hi Andy Ainscow,
 
     I can't put following my question on experts-exchange. Becuase, I have only 5 points. It asks 20 points per question as "Question difficulty must be at least 20 points.".
 
     my question is:
sub: How to display only one form at a time among multiple forms in SDI CFormView
desc:
     I have created SDI with CFormView. I have also created 3 different forms (form classes). I want to display at a time only one form among 3 different forms in this SDI view. Means, that diaplaying form should be override SDI current form.
    Otherwise please guide me other way about to do this.
     Please help me in this regards.
     With warm regards
     -Mahesh
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 104
Pressing cancel button with C# UI Automation 3 104
Change owner from userA to server Local Administrators 7 74
while loop over for loop 7 119
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…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.

751 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