Solved

CPropertySheet Data Update

Posted on 2003-11-03
7
639 Views
Last Modified: 2013-11-20
When a user presses OK on my property sheet...I need all the pages to update thier members...I cant call update data after DoModal...so how can I update all the pages data members before the window closes. Is there a way to override OnOK for the sheet???
0
Comment
Question by:SGyves
7 Comments
 
LVL 16

Expert Comment

by:_nn_
ID: 9675263
FWIW, I've never needed to specify something for that. I usually have

CSomeObj::OnSomeEvent()
{
    // CFirstPage is a descendant of CPropertyPage
    CFirstPage page1;
    // I've defined page1 in the ClassWizard (VC++6)
    page1.m_someField = someValue;

    // same here
    CSecondPage page2;
    page2.m_someOtherField = someOtherValue;

    CPropertySheet dlg(ID_SOME_DLG);
    dlg.AddPage(&page1);
    dlg.AddPage(&page2);

    if (dlg.DoModal()==IDOK) {
        // here I can read the variables, for instance
        someValue = page1.m_someField;
    }
}

And I don't even need to use a special sheet, the basic one is enough. And the members of the property pages are all updated as expected.

HTH
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9675269
Sorry, I meant

    // I've defined the m_someField variable in the ClassWizard (VC++6)
0
 

Author Comment

by:SGyves
ID: 9675928
Yeah....I had a different problem i guess......this was okay.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9676052
Map all CpropertyPage's OnOK, when clicking on CpropertySheet's OK, his will call all CPropertyPage::OnOk from CPropertSheet::OnOK. hope this helps

Rosh :)
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9676078
Some tips and tricks to change the default look&feel and behavior of CPropertySheet class  
http://www.codeproject.com/property/hacking_the_cpropertyshee.asp - Hacking the CPropertySheet

Rosh :)
0
 

Expert Comment

by:himch
ID: 9676479
Hi

You can write your update code on the OnOK() on every property page. All those pages, which have been changed/accessed call their OnOK() when you press OK of the property sheet.
This should solve the problem.

Himanshu
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 300 total points
ID: 9677324
My technique is a little bit uniusual, but it has served me well.

I derive an object from CPropertySheet and I add a few functions
      LoadPages()
and
     SavePages()

Its .H file has a bunch of lines like this:
    CDlgPgMain       m_cPgMain;
    CDlgPgOptions   m_cPgOptions;
    CDlgPgLogging   m_cPgLogging;

so my LoadPages() starts out like this

      AddPage( &m_cPgMain );
      AddPage( &m_cPgOptions );
      AddPage( &m_cPgLogging );
      //------------------------------------------------------------ Load Up Main
      m_cPgMain.m_sEdit1="intital value";
      m_cPgMain.m_sEdit2= ... some value from the registry/Profile...
      //------------------------------------------------------------ Load Up Options
      m_cPgOptions.m_Edit1="intital value";
      ... etc...

And my SavePages() has a similar sequence, but in reverse:

      //------------------------------------------------------------ Save Main
      gSavedValue= m_cPgMain.m_sEdit1;
      PrgPrefs.sSomeOption- cPgMain.m_Edit2;
      //------------------------------------------------------------ Save Options
      WriteToDatabase( "yadaYada", m_cPgOptions.m_Edit1 );
      ... etc...

=-=-=-=-=-=-=-=-=-=-=-
One value of this technique is that all of the data is assigned and checked in one place... you don't have hunt down each CPropertyPage-derived object.

I (sometimes)  have a
      CanSave()
function that checks all of the data (also with a parallel set of line-items in the code).  If something is no good (some combination of conflicting values that the individula pages can't avoid easily, etc), then CanSave() fails.  It pops up a message box, and then activates the correct page.

In my CProprtySheet, I intercept OK and do not let the OK command finish if CanSave() fails.   Here is how I do that...

//------------------------------------------------------------
BOOL CDlgSheetABC::OnCommand(WPARAM wParam, LPARAM lParam)
{
      if ( wParam == IDOK ) {
            CPropertyPage* pPg= GetActivePage();
            pPg->UpdateData();
            if ( !CanSave() ) {
                  return( TRUE );  // yes, done processing (do nothing)
            }
      }
      return CPropertySheet::OnCommand(wParam, lParam);
}

And to start the whole thing...

      CDlgSheetABC cSheet( "Info", NULL, 0 /*iSelectPage*/ );
      cSheet.LoadPages();
      int iRet;
      while( TRUE ) {   // exit via break
            iRet= cSheet.DoModal();  //----------------- Edit the data
            if ( iRet != IDOK ) {
                  break;
            }
            if ( cSheet.SavePages() ) { // FALSE only on oddbal error or user cancel
                  break;
            }
      }
      return( iRet == IDOK );
}
=-=-=-=-=-=-=-=-
This technique has served me well.

-- Dan
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Detect CR LF to each line 12 160
post4 challenge 28 100
child constructor and parent constructor, overriding and overloading 6 84
Sed question 2 85
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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