

The SetRefDataSource property is used to bind the ADO Recordset generated to the control. M_ctlDataGrid.SetRefDataSource( (LPUNKNOWN) m_pRS ) M_pRS- >Open((LPCSTR)sTableName,(LPCSTR)pMainFrame- >ĪdOpenKeyset,adLockOptimistic, adCmdTable) M_pRS.CreateInstance( _uuidof(Recordset)) Class wizard will bind the CDataGrid class with the control.Ĭopy Code void CDataGridView::UpdateGridDetails( const CString& sTableName)ĬMainFrame* pMainFrame = reinterpret_cast (AfxGetMainWnd()) Use the Class Wizard in the normal way to bind the control to a Dialog or Formview. Bind the DataGrid to a Dialog or Formview The CDataGrid class will have been generated for you in DataGrid.h and DataGrid.CPP, these files will also have been added to your project. Go to the Resource editor, you should see the MS DataGrid Control added to your collection of controls that you can use. You only need the CDataGrid class for this sample, therefore check only this class. Then press the insert button, the following dialog will appear: Select the Registered ActiveX Control folder from the dialog and find Microsoft DataGrid Control, Version 6 (OLEDB). Project->Add to project->Components and Controls You need to add the DataGrid control to your project, this is done in the usual way via: Tools->Options->Directories->Include Files Adding the DataGrid Control to the Project Please note that you may need to add the full path to these DLLs or you can add the path through your visual C++ environment via: #import Oledb32.dll // this contains the Data Source Locator COM Interface In order to use the ADO COM object, you will need to import the following type libraries, this should be done in your stdafx.h file.Ĭopy Code #import msado15.dll // This contains the ADO Type Library. This contains the OLE DB drivers that are required to hook up to the database or the data source.Ī good knowledge of ADO (ActiveX Data Object) is also required to understand the binding process to the DataGrid. MDAC v2.1 or higher (this can be obtained from Microsoft). You can find information on the DataGrid control and its properties on MSDN. The sample has been tested with both MS Access and SQL Server, in theory, you should be able to use it against all data sources that support OLE-DB. This is a simple implementation that shows you how to use the MS DataGrid control with ADO. The Microsoft DataGrid is usually seen associated with VB when you start searching for information on how to implement the MS DataGrid in Visual C++. There is not a lot of information out there and therefore many Visual C++ programmers tend not to use this excellent and easy to use database control.
