?
Solved

MFC and SDI with TREEVIEW and FORMVIEW

Posted on 1998-05-17
3
Medium Priority
?
1,361 Views
Last Modified: 2013-11-20
I am using an SDI with a two pane splitter.  The left pane is a treeview and the right pane is a form view.  I have a CRecordset derived class to populate the tree and the form.  Currently, I am populating the tree in the application's view class using OnInitialUpdate function.  

How can I populate and synchronize the data in the formview (or should it be recordview?) with the selected tree item?
Should I be using a global pointer for the Recordset and if so how and where should I implement it?

I am using ODBC on a remote UNIX database.

TIA

Pat...
0
Comment
Question by:patrickm
[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 15

Accepted Solution

by:
Tommy Hui earned 300 total points
ID: 1311698
You would probably want the treeview to send a message to the CFormView to tell it that a new selection has taken place. The method I will be describing is for the more generic case.

Define the structure for the memory that will be shared between the view (in this case, it can be a simple as an HTREEITEM or the data pointed to by HTREEITEM (such as the text) or both).

  struct XferData
  {
    HTREEITEM m_TreeItem;
    TCHAR m_Buffer[2048];
  };

Create a global variable of this type.

  XferData g_XferData;

In your tree's selected item member function, populate the g_Xferdata and use

  GetDocument()->UpdateAllViews(this, hint_XferData, (CObject*)&g_XferData);

to send the hint_XferData message to all the views. Not all of the views care about this message, so modify the CFormView's OnUpdate to know about this message:

  void CMyFormView::OnUpdate(CView* sender, LPARAM hint, CObject* obj)
  {
    if (hint == hint_XferData)
    {
      XferData* xferData = (XferData*)obj;
      // use xferData to display the correct record
    }
    else
      CFormView::OnUpdate(sender, hint, obj);
  }

hint_XferData is a number that you defined that is larger than 100 and must be unique to your document/view hint ids.
0
 

Expert Comment

by:cmliu
ID: 1311699
Check the MFC samples DaoView, use document to store data and synchronize the two views. (it needn't be recordview). Use CDocument 's UpdateAllViews to update all views, use invalidate to only update one view. It is better to store the right view pointer to access it more easily.
0
 

Author Comment

by:patrickm
ID: 1311700
Thank you Thui, but I am weak on MSVC and its Appwizard gen'd classes.  Where is the appropriate place to put these globals and what about a globally defined recordset pointer.  I have pointers to the two view classes defined in the document class (m_pTreeView, m_pFormView). It appeared that they might be useful, but how do I use them?

BTW could you explain 'hint' a little further.

TIA
Pat...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 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