method G2antt.BeginUpdate ()

Maintains performance when items are added to the control one at a time.

 TypeDescription 

This method prevents the control from painting until the EndUpdate method is called. 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. You can use the FreezeEvents method to prevent the control to fire any event.

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

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

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;
	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 );
			CColumns columns = m_g2antt.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_g2antt.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.SetCellValue( vtI, _variant_t( j ), spRecordset->Fields->Item[ j ]->Value );
					spRecordset->MoveNext();
				}
			}
			m_g2antt.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 AxG2antt1
    .BeginUpdate()
    With .Columns
        .Add("Column 1")
        .Add("Column 2")
    End With
    With .Items
        Dim iNewItem As Integer
        iNewItem = .AddItem("Item 1")
        .CellValue(iNewItem, 1) = "SubItem 1"
        iNewItem = .AddItem("Item 2")
        .CellValue(iNewItem, 1) = "SubItem 2"
    End With
    .EndUpdate()
End With

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

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

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

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

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

 


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