Adds an array of integer, long, date, string, double, float, or variant arrays to the control, beginning at Index.
![]() | Type | Description | ||
| Items as Variant | An array that control uses to fill with | |||
| Index as Variant | Reserved. Only for future use. |
Use the PutItems property when you have a table of elements stored by an array. Use the GetItems method to get a safe array with the items in the control. Use the Items property to access the items collection. Use the AddItem method to add items one by one. Use the DataSource property to bind the control to an ADO or DAO recordset. Use the ColumnAutoResize property to specify whether the visible columns should fit the control's client area. Use the ConditionalFormats method to apply formats to a cell or range of cells, and have that formatting change depending on the value of the cell or the value of a formula.
The following VB sample loads an array to your control:
With Gantt1
.BeginUpdate
.Columns.Add "Column 1"
.PutItems Array("Item 1", "Item 2", "Item 3")
.EndUpdate
End With
For instance the following VB sample loads an array of strings.
Dim v(2, 2) As String v(0, 0) = "One" v(0, 1) = "Two" v(0, 2) = "Three" v(1, 0) = "One" v(1, 1) = "Two" v(1, 2) = "Three" v(2, 0) = "One" v(2, 1) = "Two" v(2, 2) = "Three" Gantt1.BeginUpdate Gantt1.Columns.Add "Column 1" Gantt1.Columns.Add "Column 2" Gantt1.Columns.Add "Column 3" Gantt1.PutItems v Gantt1.EndUpdate
The following VB sample loads an ADO recordset using PutItems method:
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
Gantt1.BeginUpdate
For Each f In rs.Fields
Gantt1.Columns.Add f.Name
Next
Gantt1.PutItems rs.GetRows()
Gantt1.EndUpdate
The following C++ sample loads records from an ADO recordset, using the PutItems method:
#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_gantt.BeginUpdate();
m_gantt.SetColumnAutoResize( FALSE );
CColumns columns = m_gantt.GetColumns();
for ( long i = 0; i < spRecordset->Fields->Count; i++ )
columns.Add( spRecordset->Fields->GetItem(i)->Name );
COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR;
m_gantt.PutItems( &spRecordset->GetRows(-1), vtMissing );
m_gantt.EndUpdate();
}
}
catch ( _com_error& e )
{
AfxMessageBox( e.Description() );
}
}
The sample uses the #import statement to import ADODB recordset's type library. The sample enumerates the fields in the recordset and adds a new column for each field found. Also, the sample uses the GetRows method of the ADODB recordset to retrieves multiple records of a Recordset object into a safe array. Please consult the ADODB documentation for the GetRows property specification.