Solved

MFC and SDI with TREEVIEW and FORMVIEW

Posted on 1998-05-17
3
1,330 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
3 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 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

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
xyBalance chalenge 58 96
deburging in oracle form 12 105
Remove Password Protection from pdf (with password) using an command line executable 5 62
Problem to App 4 97
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

861 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