Type | Description | |||
Object | An ADO or DAO Recordset object used to fill data from. |
The /NET version provides the following methods for data binding:
Using the data binding on /NET may change the following properties:
Click here to watch a movie on how to assign a data source to the control, in design mode, for /NET assembly.
The following VB sample binds an ADO recordset to the ExG2antt/COM 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 G2antt1.DataSource = rs
The DataSource clears the columns collection, and load the recordset to the control. 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_g2antt.BeginUpdate(); m_g2antt.SetColumnAutoResize( FALSE ); m_g2antt.SetDataSource( spRecordset ); m_g2antt.EndUpdate(); } } catch ( _com_error& e ) { AfxMessageBox( e.Description() ); } }
The #import statement imports definitions for ADODB type library, that's used to fill the control.
The following C# sample binds at runtime a table to the /NET component, using the DataSource property:
private DataTable GetTable() { DataTable table = new DataTable(); table.Columns.Add("Dosage", typeof(int)); table.Columns.Add("Drug", typeof(String)); table.Columns.Add("Patient", typeof(String)); table.Columns.Add("DateIn", typeof(DateTime)); table.Columns.Add("DateOut", typeof(DateTime)); table.Rows.Add(25, "Indocin", "David", DateTime.Today, DateTime.Today.AddDays(2)); table.Rows.Add(50, "Enebrel", "Sam", DateTime.Today.AddDays(2), DateTime.Today.AddDays(4)); table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Today.AddDays(4), DateTime.Today.AddDays(8)); table.Rows.Add(21, "Combivent", "Janet", DateTime.Today.AddDays(2), DateTime.Today.AddDays(6)); table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Today.AddDays(1), DateTime.Today.AddDays(3)); return table; } private void Form1_Load(object sender, EventArgs e) { Exgantt1.BeginUpdate(); Exgantt1.DefaultItemHeight = 25; Exgantt1.DataSource = GetTable(); Exgantt1.Chart.LevelCount = 2; Exgantt1.EndUpdate(); }
The following VB.NET sample binds at runtime a table to the /NET component, using the DataSource property:
Function GetTable() As DataTable Dim table As DataTable = New DataTable() table.Columns.Add("Dosage", GetType(Long)) table.Columns.Add("Drug", GetType(String)) table.Columns.Add("Patient", GetType(String)) table.Columns.Add("DateIn", GetType(DateTime)) table.Columns.Add("DateOut", GetType(DateTime)) table.Rows.Add(25, "Indocin", "David", DateTime.Today, DateTime.Today.AddDays(2)) table.Rows.Add(50, "Enebrel", "Sam", DateTime.Today.AddDays(2), DateTime.Today.AddDays(4)) table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Today.AddDays(4), DateTime.Today.AddDays(8)) table.Rows.Add(21, "Combivent", "Janet", DateTime.Today.AddDays(2), DateTime.Today.AddDays(6)) table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Today.AddDays(1), DateTime.Today.AddDays(3)) GetTable = table End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With Exgantt1 .BeginUpdate() .DefaultItemHeight = 25 .DataSource = GetTable() .Chart.LevelCount = 2 .EndUpdate() End With End Sub