Solved

using property sheets

Posted on 2002-04-12
3
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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