method Tree.EndUpdate ()

Resumes painting the control after painting is suspended by the BeginUpdate method.

TypeDescription

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 adding data from a database:

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

Tree1.BeginUpdate
For Each f In rs.Fields
    Tree1.Columns.Add f.Name
Next
Tree1.PutItems rs.GetRows()
Tree1.EndUpdate

The following VC 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;
	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 );
			CColumns columns = m_tree.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 );
				CItems items = m_tree.GetItems();
				// Adds the items
				while ( !spRecordset->adoEOF )
				{
					long j = 0;
					_variant_t vtI( items.AddItem( spRecordset->Fields->Item[ j ]->Value ) );
					for ( ++j ; j < nCount; j++ )
						items.SetCellCaption( vtI, _variant_t( j ), spRecordset->Fields->Item[ j ]->Value );
					spRecordset->MoveNext();
				}
			}
			m_tree.EndUpdate();
		}
	}
	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 AxTree1
    .BeginUpdate()
    With .Columns
        .Add("Column 1")
        .Add("Column 2")
    End With
    With .Items
        Dim iNewItem As Integer
        iNewItem = .AddItem("Item 1")
        .CellCaption(iNewItem, 1) = "SubItem 1"
        iNewItem = .AddItem("Item 2")
        .CellCaption(iNewItem, 1) = "SubItem 2"
    End With
    .EndUpdate()
End With

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

axTree1.BeginUpdate();
EXTREELib.Columns columns =axTree1.Columns;
columns.Add("Column 1");
columns.Add("Column 2");
EXTREELib.Items items = axTree1.Items;
int iNewItem = items.AddItem( "Item 1" );
items.set_CellCaption( iNewItem, 1, "SubItem 1" );
items.InsertItem( iNewItem, "", "Child 1" );
iNewItem = items.AddItem( "Item 2" );
items.set_CellCaption( iNewItem, 1, "SubItem 2" );
axTree1.EndUpdate();

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

thisform.Tree1.BeginUpdate()
with thisform.Tree1.Columns
	.Add("Column 1")
	.Add("Column 2")
endwith

with thisform.Tree1.Items
	.DefaultItem = .AddItem("Item 1")
	.CellCaption(0, 1) = "SubItem 1"
	.DefaultItem = .InsertItem(.DefaultItem,"","Child 1")
	.CellCaption(0, 1) = "SubChild 1"
endwith
thisform.Tree1.EndUpdate()