We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Update a CFormView from CMyDoc

joakimf asked
Medium Priority
Last Modified: 2013-11-19
I have a CFromView with three Edit boxes, and when I´ve opened a file using serialize in CMyDoc I would like to update my three variables in CMyView and then update my Window so that it shows my variables. I´m a newbie and are there anybody who knows a good and easy way to do this, I´d appriciate the code written out. Thanx...
Watch Question

The easiest way is to use classwizrd to define variable for each of the edit boxes using the members variable tab

Lets say the variable are called m_Var1,m_Var2,m_Var3
they should be public tby default
so you can use somthing like
 MyView->m_var = xxxx etc etc
The use UpdateData( FALSE ) to transfer data from the variable to the control. UpdateData( TRUE ) will do the oposite when you want to update the variable ready for storing
Hope this at least gets you started


I´m sorry I didn´t state my question clear enough I try to be more specific.
I´ve got the variables through ClassWizard but I can´t use them in CMyDoc because I don´t know how to create a pointer to the CMyView class. I´ve tried to set
CMyView* pView=GetFirstView();
It doesn´t work, so I would like some help how to do something like that.
How have you created CMyView. If its done through a doc template then it should be added to the doc by the framework.  if not when you create the view call pDoc->AddView( pMyView );
Then when you call getFirstview/ Get next view you will have to use the pView->IsKindOf(RUNTIME_CLASS(CMyView) ) to ensure that the ptr is pointing to you class. Then you should be able to set the variable


CMyView was created when I made the project in MFC App Wizard, and one of the problem is that I can´t include CMyView.h in the CMyDoc.cpp file som I don´t reach the CMyView class in CMyDoc when i try to compile I get error saying that the variables are unidentified.
Maybe it wasn´t such an easy question so I´ve increased the points.
I don't see why you can't include the header file. Post the code
for the Doc and View ( headers as well) as it help ( or just email them to me if you dont want to make them public) keyan01@cai.com


Okey, will do as soon as possible..
I never have the document access the view directly.  I use CDocument::UpdateAllViews(); and have the view use its GetDocument() and get the data accordingly.
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview


Thanx for your comment danny_pav, but my real problem is hoe to transfer data from a global variable to my variables in CMyView wich are connected to my edit boxes...

While I am writing the answer, danny_pav provided a similiar comment. I think you declared some variable corresponding to those in CView. Use the pointer *pDoc in View, you can access the variables you declared in CDoc. Try it. There should be no problem.


Thanx trestan, it worked perfectly. Enjoy the points....
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.