• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1405
  • Last Modified:

MFC and SDI with TREEVIEW and FORMVIEW

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
patrickm
Asked:
patrickm
1 Solution
 
Tommy HuiCommented:
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
 
cmliuCommented:
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
 
patrickmAuthor Commented:
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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now