This sample illustrates three ways of Essential Grid population. The first technique loops through the cells and uses an indexer on the GridControl to set values. The second technique uses the PopulateValues() method to optimally place data from a data source into a grid range. The last technique uses Essential Grid in a virtual manner.
Features
Indexer Technique
for (int i = 0; i < this.numArrayRows; ++i) for(int j = 0; j < this.numArrayCols; ++j) this.gridControl1[i + 1, j + 1].CellValue = this.intArray[i,j];
PopulateValues() Method
gridControl1.Model.PopulateValues(GridRangeInfo.Cells(top, left, bottom, right), this.intArray);
Virtual Mode
Three handlers are to be used:
this.gridControl1.QueryCellInfo += new GridQueryCellInfoEventHandler(QueryCellInfoHandler); this.gridControl1.QueryColCount += new GridRowColCountEventHandler(GridQueryColCount); this.gridControl1.QueryRowCount += new GridRowColCountEventHandler(GridQueryRowCount);
The QueryColCount and QueryRowCount are the events that are used to return the column and row count that are in demand.
Data from the data source is set through the QueryCellInfo handler.
It can be noted that for more than 5,000 cells, the virtual mode is far better than the PopulateValues() method.
The grid is purely virtual only when the e.Handled property is set to true.
When you run this sample, you can specify the size of the grid that is to be populated, and then you can try all three methods to compare their performance. However, be aware that the .NET Framework JIT will make the first population a little slower because of the one-time jitting of the code.
This sample also uses the OperationFeedback class to provide a progress bar in the first population technique to allow you to potentially cancel a long operation.