Add the content of the database to the tree control. Create a database and connect it with the tree control to access the database. The query structure is clear and easy to operate.
The method is described as follows:
1. Create a database: Create an Access database. For the database structure and content, see the access file of the package.
2. Creating a single document is not based on the Application project supported by the database. The View class inherits from CFormView.
Project name: Ppp, and view class name: CPppView.
3. Create a database set. The data source uses DAO connection and inherits from CDaoRecordset. The class name is CShengSet.
4. Add the data source header file supporting DAO connection to the Stdafx. h file.
# Include <afxwin. h>// MFC core and standard components
# Include <afxext. h>// MFC extensions
# Include <afxdisp. h>// MFC Automation classes
# Include <afxdao. h>// Add rows to Access the Access database of this view class
# Include <afxdtctl. h>// MFC support for Internet Explorer 4 Common Controls
# Ifndef _ AFX_NO_AFXCMN_SUPPORT
# Include <afxcen. h>// MFC support for Windows Common Controls
# Endif
5. Add the dataset header file to PppView. h.
# Include "ShengSet. h"
Define dataset variables at the same time
Public:
CShengSet* M_ShengSet;
6. Add the dataset header file to PppDoc. h.
# Include "ShengSet. h"
Define dataset variables at the same time
Public:
CShengSetM_ShengSet;
7. Add the tree control (IDC_TREE1) to the View class dialog box and define its variable name as m_treectrl;
8. Obtain the pointer to the dataset in the OnInitialUpdate () function of the PppView. cpp file.
CFormView: OnInitialUpdate ();
CPppDoc * pDoc = (CPppDoc *) GetDocument (); // get a pointer to the document class
& N