CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2002
    Posts
    30

    Updating CDocument data from view

    Hi,

    I'm writing a SDI app. which has edit/combobox/list controls on the CFormView based dialog. All the controls have a variable (CString most of them) on the CDocument class waiting to receive their values. What would be the best way to update these variables before serialize them using the "Save" button on the toolbar? Should i map messages like ON_CBN_KILLFOCUS for each control and update them one by one? Or should i get, somehow, these values from the CDocument itself inside the serialize function?

    Thanks in advance.

    Ric

    P.S. I'm new on SDI/MDI. Dialog based app so far.]
    P.S.2 I researched the forum but didn't find any clarification on this.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635
    MSDN says

    Implement a member function to move data from your view to your document.
    This member function is typically a message handler for a control-notification message or for a menu command. If you are using DDX, call the UpdateData member function to update the member variables in your view class. Then move their values to the document associated with the form view.

  3. #3
    Join Date
    Jul 2002
    Posts
    30
    Ok. Let's say I have the OnFileSave handler (for the toolbar "save" button) inside my cview class. I write my code so that the variables in the Cdocument are updated. How can I keep calling the OnFileSave/Serialize handler in the CDocument?Is that possible? I've read that the the application framework starts looking for message handlers in the view/document sequence. I'd like to avoid having to push other button besides the Save one.

    Thanks again,

    Ric

  4. #4
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917
    Usually form view is used to collect data from user.
    Use Serialize member of the view to store form’s data.
    Call that member from Serialize member of the document.

    After view’s data is retrieved from file use data members of the view to initialize members of the document if needed.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  5. #5
    Join Date
    Jul 2002
    Posts
    30
    I'm using the form to get user data, just that. However I do some sort of processing (very simple) before saving data to disk and my intention was to have this processing under the serialize function on CDocument, so I need the updated values from controls.

    Since I hava some more info. to save, not from view, I would like to avoid calling calling view->serialize from CDocument (if I undestood correctly John's post )

    Currently I update the Cdocument variables (associated to the form controls) everytime each control looses focus. But I do know this is not the best approach.

    Any other idea? Thanks once more.

    Ric

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635
    Quote Originally Posted by RIC_V
    Ok. Let's say I have the OnFileSave handler (for the toolbar "save" button) inside my cview class. I write my code so that the variables in the Cdocument are updated. How can I keep calling the OnFileSave/Serialize handler in the CDocument?Is that possible? I've read that the the application framework starts looking for message handlers in the view/document sequence. I'd like to avoid having to push other button besides the Save one.

    Thanks again,

    Ric
    You can call CDocument::OnSaveDocument() any time you like.

  7. #7
    Join Date
    Jul 2002
    Posts
    30
    I called CDocument::OnSaveDocument() from my view as suggested. I endup having to implement the dialog for getting user file name/directory myself (if I didn't miss something here).

    Since I would like to keep the default behaviour (i.e. having the framework handle this) I was thinking about building a funcion (inside my CFormview) which will be in charge of updating the variables in the document. So everytime the user save the data, I call this function from CDocument, just before serialize them. Do you guys see any problem with that?

    Regards,

    Ric

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635
    Quote Originally Posted by RIC_V
    I called CDocument::OnSaveDocument() from my view as suggested. I endup having to implement the dialog for getting user file name/directory myself (if I didn't miss something here).

    Since I would like to keep the default behaviour (i.e. having the framework handle this) I was thinking about building a funcion (inside my CFormview) which will be in charge of updating the variables in the document. So everytime the user save the data, I call this function from CDocument, just before serialize them. Do you guys see any problem with that?

    Regards,

    Ric
    That's what MSDN suggested in the quote I posted almost. Just write an ID_FILE_SAVE handler in the view, call UpdateData(), then call the default handler.

  9. #9
    Join Date
    Jul 2002
    Posts
    30
    Didn't find a way to call the "default Handler" which i assumed was the handler in the CDocument Class (protected). What I did was to change the ID for the "Save button", add a handler for it (where I finally do my update) and then post a message calling the "default handler".

    PostMessage( WM_COMMAND, ID_FILE_SAVE );

    It's working as intended.

    Thank you all.

    Ric

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured