Solved

using property sheets

Posted on 2002-04-12
3
197 Views
Last Modified: 2013-11-20
I have an application that has a propertySheet with two propertyPages. The first page contains the person's name and address. The second page contains the person's name and some other information. In addition on each page I have a 'next' and 'prev' buttons that goes to the next or previous personnel record.
1) how can I load the person's name on both pages at once? Can I do it on the onInitDlg event of the propertySheet? (actually there is more information repeated on each page than the person's name)
2) how do I load and save the data from each page? do I have to do it when going in and out of each page? or can I do it when the 'next' or 'prev' buttons are pressed?

thanks
0
Comment
Question by:el_rooky
3 Comments
 
LVL 3

Expert Comment

by:Crius
ID: 6937117
The property sheet is a common place to store things that can be accessed by all property pages. If you want to have the name appear on more than 1 page, you'll have to store it there.

Each property page is a window, a dialog like window that is hidden when you move from one page to another. They will maintain their state even after you've moved to another property sheet.

You can not load the name onto the property pages with OnInitDialog because that is only called once. You could likely do it in the property sheet when it detects a tab change (think of the property sheet as like a tab control where each tab references a property sheet), or you could have it read from the property sheet when the window becomes visible, or active...

There is no need to load or save data for each page since when you leave the page, the data does not go away. You can attach the data to variables using the class wizard though, and when the property sheet is closed, just iterate through all the property pages making use of the variables as you see fit..
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 150 total points
ID: 6938622
There are several ways to do this, and it takes some planning.  I assume that you have a CRecordset that contains the personell records.  You need to make that available to both pages.

The simplest way to do that is to make it a global variable.  The object-oriented way to do that is to make it a member of the CPropertySheet-derived object that contains both pages.  I'll assume the latter and call the propertysheet object CMySheet and assume that it has a recordset member named m_cRecSetPersonell.

When you instantiate CMySheet, open the recordset and populate all of the fields of all of the pages:

CMySheet cSheet( "My title" );

cSheet.AddPage( m_cPg1 );
cSheet.AddPage( m_cPg2 );

m_cRecSetPersonell.Open(....)

cSheet.m_cPg1.m_sLastName= m_cRecSetPersonell.m_LastName;
cSheet.m_cPg2.m_sSalary=   m_cRecSetPersonell.m_Salary;
(etc)

cSheet.DoModal();

==--=-==-
Next, you need to do somthing like this in the on click handlers in both pages:

void CDlgPg_1::OnNext()
{
   CMySheet* pSheet= (CMySheet*)GetParent();
   pSheet->m_RecSetPersonell.MoveNext();
   m_lastName= pSheet->m_RecSetPersonell.m_LastName;
   ...(etc)...
   UpdateData( FALSE ); // display the data
}

Finally, when the user clicks th tab to view the other page, you need to updat the data there, also.  So add an OnSetActive handler:

void CDlgPg_1::OnSetActive()
{
   CMySheet* pSheet= (CMySheet*)GetParent();
   pSheet->m_RecSetPersonell.MoveNext();
   m_lastName= pSheet->m_RecSetPersonell.m_LastName;
   ...(etc)...
   UpdateData( FALSE ); // display the data
}

=-=-=-=-
Notice that both fns do the same thing, so you might as well right a member fn that transfers the data from the recordset into the member variables and then calls UpdateData(FALSE).  And why put it in two places?  Instead, you could add a member to CMySheet that uses code like:

void CMySheet::LoadVars()
{
   m_cPg1.m_LastName= m_RecSetPersonell.m_LastName;
   ...(etc)...
   m_cPg2.m_Salary= m_RecSetPersonell.m_Salary;
   ...etc..
}

Then both your OnSetActivate and OnSomeButton hander could call:

   CMySheet* pSheet= (CMySheet*)GetParent();
   pSheet->LoadVars();
   UpdateData( FALSE );

You could also call LoadVars() right before cSheet.DoModal().

=-=-=-=-=-=-=-=-=-=-=-=-
If there is any part of this that you don't understand, I'll be glad to explain.

-- Dan
0
 

Author Comment

by:el_rooky
ID: 6942801
Dan,
It works great!
Thanks a lot.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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
MFC Dialog 9 51
Unix / Linux grid computing 5 163
Detect file exist or not 3 178
Is there a simple front-end menu system. 9 103
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.

839 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