Solved

MFC and SDI with TREEVIEW and FORMVIEW

Posted on 1998-05-17
3
1,309 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 85
lucky13 challenge 11 111
wait notify demo infinite loop 3 79
wordcount challenge 11 71
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…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now