Solved

using property sheets

Posted on 2002-04-12
3
196 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 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