Xceed Grid for WinForms v4.3 Documentation
Batch Modifications

Welcome to Xceed Grid for WinForms v4.3 > Advanced Concepts > Batch Modifications

Xceed Grid for WinForms provides support for transactional operations during batch modifications (to the grid or its elements) through its implementation of the ISupportInitialize interface. During transactional operations, data will not be loaded into the grid, sorting operations will not be done and the visible positions of columns will not be resequenced.

Performing batch modifications

Batch modifications begin with a call to the grid's BeginInit method and end with a call to the EndInit method. When EndInit is called, the data will be loaded into the grid (if any data binding occurred during the process), data rows will be sorted (if a sort operation was requested) and the visible positions of columns will be resequenced (if the VisibleIndex properties of columns were modified).

For example, let's assume that the following columns start in the following visible positions.

See example

VB.NET
Copy Code
grid.Columns( 0 ).VisibleIndex = 0
grid.Columns( 1 ).VisibleIndex = 1
grid.Columns( 2 ).VisibleIndex = 2
grid.Columns( 3 ).VisibleIndex = 3
C#
Copy Code
grid.Columns[ 0 ].VisibleIndex = 0;
grid.Columns[ 1 ].VisibleIndex = 1;
grid.Columns[ 2 ].VisibleIndex = 2;
grid.Columns[ 3 ].VisibleIndex = 3;
Set the visible position of the 1st and second columns between calls to the BeginInit and EndInit methods

See example

VB.NET
Copy Code
grid.BeginInit()
grid.Columns( 0 ).VisibleIndex = 2
grid.Columns( 1 ).VisibleIndex = 3
grid.EndInit()
C#
Copy Code
grid.BeginInit();
grid.Columns[ 0 ].VisibleIndex = 2;
grid.Columns[ 1 ].VisibleIndex = 3;
grid.EndInit();
As a result, the columns would then possess the following visible positions since the visible positions of the columns will only be resequenced when EndInit is called.

See example

VB.NET
Copy Code
grid.Columns( 0 ).VisibleIndex = 0
grid.Columns( 1 ).VisibleIndex = 2
grid.Columns( 2 ).VisibleIndex = 1
grid.Columns( 3 ).VisibleIndex = 3
C#
Copy Code
grid.Columns[ 0 ].VisibleIndex = 0;
grid.Columns[ 1 ].VisibleIndex = 2;
grid.Columns[ 2 ].VisibleIndex = 1;
grid.Columns[ 3 ].VisibleIndex = 3;

If the visible positions of the columns would have been changed outside of calls to BeginInit and EndInit, the result would have been:

See example

VB.NET
Copy Code
grid.Columns( 0 ).VisibleIndex = 1
grid.Columns( 1 ).VisibleIndex = 3
grid.Columns( 2 ).VisibleIndex = 0
grid.Columns( 3 ).VisibleIndex = 2
C#
Copy Code
grid.Columns[ 0 ].VisibleIndex = 1;
grid.Columns[ 1 ].VisibleIndex = 3;
grid.Columns[ 2 ].VisibleIndex = 0;
grid.Columns[ 3 ].VisibleIndex = 2;
When binding the grid to a data source by setting the DataSource and DataMember properties or calling the SetDataBinding method during calls to BeginInit and EndInit, the column definitions (not their values) are still read from the data source. This behavior was implemented in order to provide access to the grid's columns during a transactional data binding process. 

Although the column definitions are read during calls to BeginInit and EndInit, the data rows are not loaded into the grid until EndInit is called. If the grid's data binding is reset during calls to BeginInit and EndInit, all the data rows currently in the grid will be cleared however, the grid will not be populated with the new data rows until EndInit is called.