Type | Description | |||
Object | An ADO or DAO Recordset object used to fill data from. |
The /NET version provides the following methods for data binding:
The following VB sample binds an ADO recordset to the ExTree control:
Set rs = CreateObject("ADODB.Recordset") rs.Open "Orders", "Provider=Microsoft.Jet.OLEDB.3.51;Data Source= D:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB", 3 ' Opens the table using static mode Set Tree1.DataSource = rs
The DataSource clears the columns collection, and fill the record set into the tree, like a list. Use SetParent method to make your list a hierarchy.
The following C++ sample binds a table to the control:
#include "Items.h" #include "Columns.h" #include "Column.h" #pragma warning( disable : 4146 ) #import <msado15.dll> rename ( "EOF", "adoEOF" ) using namespace ADODB; _RecordsetPtr spRecordset; if ( SUCCEEDED( spRecordset.CreateInstance( "ADODB.Recordset") ) ) { // Builds the connection string. CString strTableName = "Employees", strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="; CString strPath = "D:\\Program Files\\Microsoft Visual Studio\\VB98\\NWIND.MDB"; strConnection += strPath; try { // Loads the table if ( SUCCEEDED( spRecordset->Open(_variant_t( (LPCTSTR)strTableName ), _variant_t((LPCTSTR)strConnection), adOpenStatic, adLockPessimistic, NULL ) ) ) { m_tree.BeginUpdate(); m_tree.SetColumnAutoResize( FALSE ); m_tree.SetDataSource( spRecordset ); m_tree.EndUpdate(); } } catch ( _com_error& e ) { AfxMessageBox( e.Description() ); } }
The #import statement imports definitions for ADODB type library, that's used to fill the control.