Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Get Ctrl Data out of SubForm Dialog to Main Dialog

Get Ctrl Data out of SubForm Dialog to Main Dialog

Scheduled Pinned Locked Moved C / C++ / MFC
questioncom
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    triggerdie
    wrote on last edited by
    #1

    Hi, While Im using subForms in my Options Dialog, i want to read out the Controls Data, like text out of a CEdit Ctrl. Normally i would do this with DDX and Classwizard -> with result I have a variable which i can use. But with the use of subForms I have no scope anymore to these subForm Dialog Elements. Im using the SubFormCollection Class from the Article "Child Dialog (Sub Forms)" from D. Zuppinger. [http://www.codeproject.com/dialog/childdlg.asp] How can i retrieve the Data out of a Control in a SubForm Dialog to my Main Dialog?! So maybe somebody out there might have an Answer with a little bit of source would be great. Thanx to all in this community Andre

    R E J 3 Replies Last reply
    0
    • T triggerdie

      Hi, While Im using subForms in my Options Dialog, i want to read out the Controls Data, like text out of a CEdit Ctrl. Normally i would do this with DDX and Classwizard -> with result I have a variable which i can use. But with the use of subForms I have no scope anymore to these subForm Dialog Elements. Im using the SubFormCollection Class from the Article "Child Dialog (Sub Forms)" from D. Zuppinger. [http://www.codeproject.com/dialog/childdlg.asp] How can i retrieve the Data out of a Control in a SubForm Dialog to my Main Dialog?! So maybe somebody out there might have an Answer with a little bit of source would be great. Thanx to all in this community Andre

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      I do not know the code, so ... The subforms are simple dialogs, so you must have a class for each dialog where you can put a member variable the one you meant by with result I have a variable . Then, I assume the subForms class must have a table of handles or pointers on the different dialogs, or something in this way. So take the index of your dialog, and try something like : CDialog *pDlg=(CDialog *)m_SubForms.m_Forms.GetAt(Index); pDlg->m_myEditCtrl // do your stuff. ~RaGE();

      T 1 Reply Last reply
      0
      • T triggerdie

        Hi, While Im using subForms in my Options Dialog, i want to read out the Controls Data, like text out of a CEdit Ctrl. Normally i would do this with DDX and Classwizard -> with result I have a variable which i can use. But with the use of subForms I have no scope anymore to these subForm Dialog Elements. Im using the SubFormCollection Class from the Article "Child Dialog (Sub Forms)" from D. Zuppinger. [http://www.codeproject.com/dialog/childdlg.asp] How can i retrieve the Data out of a Control in a SubForm Dialog to my Main Dialog?! So maybe somebody out there might have an Answer with a little bit of source would be great. Thanx to all in this community Andre

        E Offline
        E Offline
        eXplodus
        wrote on last edited by
        #3

        two ways. first. on the close routine of the options dialog. you send the text you wand to you parent and save it there. second. (i dont take a look on the childdlg.asp) if you use a normal dlg. with DoModal. then create your dialog on the stack not on the heap. mydialog* blub = new mydialog; blub->DoModal(); CString myvar = blub->mycstringvar; delete blub;

        1 Reply Last reply
        0
        • T triggerdie

          Hi, While Im using subForms in my Options Dialog, i want to read out the Controls Data, like text out of a CEdit Ctrl. Normally i would do this with DDX and Classwizard -> with result I have a variable which i can use. But with the use of subForms I have no scope anymore to these subForm Dialog Elements. Im using the SubFormCollection Class from the Article "Child Dialog (Sub Forms)" from D. Zuppinger. [http://www.codeproject.com/dialog/childdlg.asp] How can i retrieve the Data out of a Control in a SubForm Dialog to my Main Dialog?! So maybe somebody out there might have an Answer with a little bit of source would be great. Thanx to all in this community Andre

          J Offline
          J Offline
          Joan M
          wrote on last edited by
          #4

          I don't know what you mean with SubForm, but if the subform is a dialog placed as a control inside a parent dialog, you can use member functions in the child dialog always... I mean that is better to use member functions to get the values than getting the values directly by calling SubForm.m_CstringInEditCtrl if you use member functions (GETxxx and SETxxx in order to obtain and modify values) you'll always will be able to readapt the returned value or format the sent value as is desired... then I would do: 1. from the parent dialog/window/... you'll always have access to the childs. 2. Using the previous premise, you'll be able to call members/methods/functions from the class of the child dialog. 3. I would call methods/functions of the subform in order to get/set the desired values and in order to make it safely. Hope this helps. NOTE: Get and set are only prefixes that I use in order to use the hungarian notation and know what the function do before reading its content.

          https://www.robotecnik.com freelance robots, PLC and CNC programmer.

          T 1 Reply Last reply
          0
          • R Rage

            I do not know the code, so ... The subforms are simple dialogs, so you must have a class for each dialog where you can put a member variable the one you meant by with result I have a variable . Then, I assume the subForms class must have a table of handles or pointers on the different dialogs, or something in this way. So take the index of your dialog, and try something like : CDialog *pDlg=(CDialog *)m_SubForms.m_Forms.GetAt(Index); pDlg->m_myEditCtrl // do your stuff. ~RaGE();

            T Offline
            T Offline
            triggerdie
            wrote on last edited by
            #5

            Thanx for your fast reply. I have tried something like this what you have wrote. Problem of your Code above is that the compiler will generate an error cause of CDialog has no member m_myEditCtrl. Now i had the Idea to deriver the CDialog Class with my Dialog Class e.g. mySubFormDlgClass. The Code look something like this mySubFormDlgClass *pdlg = (mySubFormDlgClass*)m_Forms.GetAt(index); with this Construction there is no error but an Assert @ runtime! So this is not the way. Another Problem is that if i insert some AFX Messages with Classwizard into my mySubFormDlgClass,set breakpoints in this Event Functions and want to debug - there is no interruption. The Event does not occur. So only a ShowWindow takes places, no DoModal() function. Maybe there is the Problem. If i do a DoModal the Dialog opens but must be closed if i want to use my MainDialog while the other is open. I will research some time on this. Maybe you have some ideas. Thanks Andre

            R 2 Replies Last reply
            0
            • J Joan M

              I don't know what you mean with SubForm, but if the subform is a dialog placed as a control inside a parent dialog, you can use member functions in the child dialog always... I mean that is better to use member functions to get the values than getting the values directly by calling SubForm.m_CstringInEditCtrl if you use member functions (GETxxx and SETxxx in order to obtain and modify values) you'll always will be able to readapt the returned value or format the sent value as is desired... then I would do: 1. from the parent dialog/window/... you'll always have access to the childs. 2. Using the previous premise, you'll be able to call members/methods/functions from the class of the child dialog. 3. I would call methods/functions of the subform in order to get/set the desired values and in order to make it safely. Hope this helps. NOTE: Get and set are only prefixes that I use in order to use the hungarian notation and know what the function do before reading its content.

              T Offline
              T Offline
              triggerdie
              wrote on last edited by
              #6

              Hello Joan, Thanx for your fast reply. Is it possible do change dynamicly from the parentsDialog to the ChildDialog without to destroy the ChildDialog. I want to change the HIDE and SHOW behaviour of several Child Dialogs. How can I do this? Without using of DoModal() only with ShowWindow(). Cause if i do a DoModal() i can not make any interaction with my parentDialog while the ChildDialog is open. Wihtout a DoModal and just ShowWindow it does not work. Assert @ runtime. So i dont know how to solve this Problem. I want to use the Std Afx Message Functions of each Child Dialog. Maybe you have an advice. See you Andre

              1 Reply Last reply
              0
              • T triggerdie

                Thanx for your fast reply. I have tried something like this what you have wrote. Problem of your Code above is that the compiler will generate an error cause of CDialog has no member m_myEditCtrl. Now i had the Idea to deriver the CDialog Class with my Dialog Class e.g. mySubFormDlgClass. The Code look something like this mySubFormDlgClass *pdlg = (mySubFormDlgClass*)m_Forms.GetAt(index); with this Construction there is no error but an Assert @ runtime! So this is not the way. Another Problem is that if i insert some AFX Messages with Classwizard into my mySubFormDlgClass,set breakpoints in this Event Functions and want to debug - there is no interruption. The Event does not occur. So only a ShowWindow takes places, no DoModal() function. Maybe there is the Problem. If i do a DoModal the Dialog opens but must be closed if i want to use my MainDialog while the other is open. I will research some time on this. Maybe you have some ideas. Thanks Andre

                R Offline
                R Offline
                Rage
                wrote on last edited by
                #7

                triggerdie wrote: cause of CDialog has no member m_myEditCtrl ... Of course your CDialog has no m_myEditCtrl variable !!! I cannot guess your variable names :rolleyes: !! This was only an exemple. Sorry for the misunderstanding. I think the articla was just a basis, you have to work on it to get your data retrieved. The easiest way to do this is the one I gave you. So, let's take it again. Change this in the code of SubFormCollection.h : instead of

                protected:
                CArray m_Forms; // array with all forms

                put

                CArray m_Forms; // array with all forms
                protected:

                This will enable you to get at the m_Forms table by setting m_Forms as public. Now you should have a main dialog, let's say CMainDlg, a CSubFormCollection, and some child dialogs, let's say CChildDlg1 and CChildDlg2 with respectively ressource IDD_SUBFORM1 and IDD_SUBFORM2 (Go in the properties of your dialogs in the ressource editor to set that). Replace these names by your variable names if they are different !!. First, follow all the steps given in the article, especially step 5 :

                CSubFormCollection m_SubForms;

                (this in the MainDlg.h file. and step 6

                CRect r;
                (GetDlgItem(IDC\_SUBFORM\_FRAME))->GetWindowRect(&r); // get the position for the subforms
                //    m\_SubForms.SetRelPos(r);  // if the positioning is absolute use this, else the next line
                m\_SubForms.SetCenterPos(r);     // centers the subdialog within the static IDC\_SUBFORM\_FRAME
                m\_SubForms.CreateSubForm(IDD\_SUBFORM1,this); // create the sub forms
                m\_SubForms.CreateSubForm(IDD\_SUBFORM2,this);
                m\_SubForms.ShowSubForm();                    
                

                (this in the CMainDlg::OnInitDlg() file.) Now you have two subForms, with index 0 and 1. Then, as an example, place an edit box on the ressource of CChildDialog1, open the class wizard, add a member variable m_myEditCtrl of type CEdit.Close the class wizard. Add a

                m_SubForms.ShowSubForm(0);

                in your code (in CMainDlg::OnInitDlg() for instance), to show the first subForm. You can now retrieve the text entered in the edit box by the user with :

                CDialog *pDlg=(CDialog *)m_SubForms.m_Forms.GetAt(0);
                CString str=pDlg->m_myEditCtrl.GetWindowText();

                Ouf :-D ... mail me directly your code if you do not get it to run, i'll be glad to help you further. ~RaGE();

                1 Reply Last reply
                0
                • T triggerdie

                  Thanx for your fast reply. I have tried something like this what you have wrote. Problem of your Code above is that the compiler will generate an error cause of CDialog has no member m_myEditCtrl. Now i had the Idea to deriver the CDialog Class with my Dialog Class e.g. mySubFormDlgClass. The Code look something like this mySubFormDlgClass *pdlg = (mySubFormDlgClass*)m_Forms.GetAt(index); with this Construction there is no error but an Assert @ runtime! So this is not the way. Another Problem is that if i insert some AFX Messages with Classwizard into my mySubFormDlgClass,set breakpoints in this Event Functions and want to debug - there is no interruption. The Event does not occur. So only a ShowWindow takes places, no DoModal() function. Maybe there is the Problem. If i do a DoModal the Dialog opens but must be closed if i want to use my MainDialog while the other is open. I will research some time on this. Maybe you have some ideas. Thanks Andre

                  R Offline
                  R Offline
                  Rage
                  wrote on last edited by
                  #8

                  OK. So i made a project and tested the article code, and found out it is totally crap. it is unfinished, sometimes even wrong (under NT, my subFroms were not getting docked in the main dialog) and the Table pointer is not reliable. X| :( Drop it ! As for your code sample, it was because you have cast the pointer on a CDialog, and not on your CDialog name (dlgOpt_ServerPort). ~RaGE();

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups