method Grid.BeginUpdate ()
Maintains performance when items are added to the control one at a time.

 TypeDescription 

The BeginUpdate method prevents the control from painting until the EndUpdate method is called.  Use BeginUpdate and EndUpdate statement each time when the control requires more changes. Using the BeginUpdate and EndUpdate methods increase the speed of changing the control properties by preventing it from painting during changing.

The following VB sample prevents the control from painting while it adds one column, and one item, using the BeginUpdate and EndUpdate methods:

With Grid1
    .BeginUpdate
        .LinesAtRoot = LinesAtRootEnum.exLinesAtRoot
        .FullRowSelect = False
        .DefaultItemHeight = 24
        With .Columns.Add("Mask")
            With .Editor
                .EditType = EditTypeEnum.MaskType
                .Appearance = SingleApp
                .Mask = "{0,255}\.{0,255}\.{0,255}\.{0,255}"
            End With
        End With
        .Items.AddItem "193.226.40.161"
    .EndUpdate
End With

The following C++ sample prevents the control from painting while adding columns and items:

#include "Column.h"
#include "Columns.h"
m_grid.BeginUpdate();
m_grid.SetColumnAutoResize( FALSE );
CColumns columns = m_grid.GetColumns();
for ( long i = 0; i < 4; i++ )
	columns.Add( "NewColumn" );
CItems items = m_grid.GetItems();
for ( long j = 0; j < 10; j++ )
{
	COleVariant vtItem( items.AddItem( COleVariant( "new item " ) ) );
	for ( long k = 1 ; k < 4; k++ )
		items.SetCellValue( vtItem, COleVariant( k ), COleVariant( "new item " ) );
}
m_grid.EndUpdate();

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

With AxGrid1
    .BeginUpdate()
    .LinesAtRoot = EXGRIDLib.LinesAtRootEnum.exLinesAtRoot
    .FullRowSelect = False
    .DefaultItemHeight = 24
    With .Columns.Add("Mask")
        With .Editor
            .EditType = EXGRIDLib.EditTypeEnum.MaskType
            .Appearance = EXGRIDLib.AppearanceEnum.Etched
            .Mask = "{0,255}\.{0,255}\.{0,255}\.{0,255}"
        End With
    End With
    .Items.AddItem("193.226.40.161")
    .EndUpdate()
End With

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

axGrid1.BeginUpdate();
EXGRIDLib.Columns columns = axGrid1.Columns;
columns.Add("Column 1");
columns.Add("Column 3");
EXGRIDLib.Items items = axGrid1.Items;
items.AddItem("new item");
items.AddItem("new item");
axGrid1.EndUpdate();

The following VFP sample prevents the control from painting while adding columns and items:

with thisform.Grid1
    .BeginUpdate
        .LinesAtRoot = .t.
        .FullRowSelect = .f.
        .DefaultItemHeight = 24
        With .Columns.Add("Mask")
            With .Editor
                .EditType = 8
                .Appearance = 1
                .Mask = "{0,255}\.{0,255}\.{0,255}\.{0,255}"
            EndWith
        EndWith
        .Items.AddItem("193.226.40.161")
    .EndUpdate
endwith

 


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