method List.EndUpdate ()
Resumes painting the control after painting is suspended by the BeginUpdate method.


The BeginUpdate and EndUpdate methods increases the speed of loading your items, by preventing painting the control when it suffers any change. Once that BeginUpdate method was called, you have to make sure that EndUpdate method will be called too.

The following VB sample prevents painting the control while the control loads data from a recordset:

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

With List1
    For Each f In rs.Fields
        .Columns.Add f.Name
    .PutItems rs.GetRows()
End With

The following C++ sample prevents refreshing the control while adding columns and items from an ADODB recordset:

#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;
		// Loads the table
		if ( SUCCEEDED( spRecordset->Open(_variant_t( (LPCTSTR)strTableName ), _variant_t((LPCTSTR)strConnection), adOpenStatic, adLockPessimistic, NULL ) ) )
			m_list.SetColumnAutoResize( FALSE );
			CColumns columns = m_list.GetColumns();
			long nCount = spRecordset->Fields->Count;
			if ( nCount > 0 )
				// Adds the columns
				for ( long i = 0 ; i < nCount; i++ )
					columns.Add( spRecordset->Fields->Item[ i ]->Name );
				m_list.PutItems( &spRecordset->GetRows(-1), vtMissing );
	catch ( _com_error& e )
		AfxMessageBox( e.Description() );

The sample adds a column for each field in the recordset, and add a new items for each record. You can use the DataSource property to bind a recordset to the control. The #import statement imports definitions for ADODB type library, that's used to fill the control.

The following VB.NET sample prevents refreshing the control while adding columns and items:

With AxList1
    With .Columns
        .Add("Column 1")
        .Add("Column 2")
    End With
    With .Items
        Dim iNewItem As Integer
        iNewItem = .Add("Item 1")
        .Caption(iNewItem, 1) = "SubItem 1"
        iNewItem = .Add("Item 2")
        .Caption(iNewItem, 1) = "SubItem 2"
    End With
End With

The following C# sample prevents refreshing the control while adding columns and items:

EXLISTLib.Columns columns = axList1.Columns;
columns.Add("Column 1");
columns.Add("Column 2");
EXLISTLib.Items items = axList1.Items;
int iNewItem = items.Add("Item 1");
items.set_Caption(iNewItem, 1, "SubItem 1");
iNewItem = items.Add("Item 2");
items.set_Caption(iNewItem, 1, "SubItem 2");

The following VFP sample prevents refreshing the control while adding new columns and items:

with thisform.List1.Columns
	.Add("Column 1")
	.Add("Column 2")

with thisform.List1.Items
	local i
	i = .Add("Item 1")
	.Caption(i, 1) = "SubItem 1"
	i = .Add("Item 2")
	.Caption(i, 1) = "SubItem 2"


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