method List.PutItems (Items as Variant, [Index as Variant])
Adds an array of integer, long, date, string, double, float, or variant arrays to the list, beginning at Index.

 TypeDescription 
   Items as Variant An array that control uses to fill with. The array can be one or two- dimensional. If the array is one-dimensional, the control requires one column being added before calling the PutItems method. If the Items parameter indicates a two-dimensional array, the first dimension defines the columns, while the second defines the number of items to be loaded. For instance, a(2,100) means 2 columns and 100 items.  
   Index as Variant Optional. 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 the items collection to a safe array. Use the Items property to access the control's items collection. Use the Add method to add new items to the control's items collection. Use the ColumnAutoResize property to specify whether the visible columns should fit the control's client area. Use the DataSource property to bind the control to an ADO or DAO recordset. 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 List1
    .BeginUpdate
    .Columns.Add "Column 1"
    .PutItems Array("Item 1", "Item 2", "Item 3")
    .EndUpdate
End With

The following VB sample loads data from a string using the " " as delimiter:

Private Sub Form_Load()
    Dim s As String
    s = "a b c d"
    
    With List1
        .BeginUpdate
        .Columns.Add "Default"
        
        .PutItems Split(s, " ")
        .EndUpdate
    End With
End Sub

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"

List1.BeginUpdate
    List1.Columns.Add "Column 1"
    List1.Columns.Add "Column 2"
    List1.Columns.Add "Column 3"
    List1.PutItems v
List1.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

List1.BeginUpdate
For Each f In rs.Fields
    List1.Columns.Add f.Name
Next
List1.PutItems rs.GetRows()
List1.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_list.BeginUpdate();
			m_list.SetColumnAutoResize( FALSE );
			CColumns columns = m_list.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_list.PutItems( &spRecordset->GetRows(-1), vtMissing );
			m_list.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.

The following VB.NET sample loads an array of elements:

With AxList1
    .BeginUpdate()
    .Columns.Add("Column 1")
    Dim c() As Integer = {1, 2, 3, 4, 5}
    .PutItems(c)
    .EndUpdate()
End With
  

 


Send comments on this topic.
1999-2017 Exontrol.COM, Software. All rights reserved.