Downloads Articles Order Sign In
Welcome to Official Berg Software web site. Twelve years with you! All other websites providing Berg Software source code and content are illegal. We will not support users who use services, or buy products from illegal Berg Software websites. more...
  Home  
  News Archive  
  Components  
  Applications  
  Downloads  
  Order  
  Support  
  About  
 
  Components
  GridView
  DBGridView
  PropertiesView
  SheetView
  Comp. Collection
 
  Applications
  Berg Player
  SMS Mara Gateway
  Domain Binocular
 
 
  Support
  Contact Us
  Support forums
  Articles
 
 
 
OPTIMIZE GRIDVIEW Home > Articles > GridView
Requirements: GridView 2.0 or newer
See Also: GridView Quick Start , How to...

GridView is very fast component. Adding rows, updating data, sorting columns, drawing cells... is very fast already, but with small tweaks you can speed up component even more.

Headlines:

1. Speed Up Adding Rows
2. How to speed-up adding/changing many cells?
3. When you don't need BeginUpdate and EndUpdate methods?
4. Chosing Column Type

Speed Up Adding Rows

As you know, to add single row in GridView, you can use GridView.AddRow() method. If you like to add multiple rows at time, you can use: GridView.AddRow(RowCount):

GridView.AddRow(100000);

So, you don't need to create for loop and to call AddRow in each pass. GridView will do this for you.

Also, adding rows will be much faster after calling AddRow(100000) once, instead of calling AddRow method 100,000 times inside loop!

How to speed-up adding/changing many cells?

Before you start with adding or changing values of huge amount of cells (typically inside some for, while, repeat...until loop), call next method:

GridView.BeginUpdate;

now add, change, move or delete cells.

after you finish, call next method:

GridView.EndUpdate;

What BeginUpdate do?

This call prevent GridView from drawing EACH new or changed Cell until operation is finished. Also all complicated calculations needed for drawing Cell is skiped too. This can speed up your code a lot!

We will draw this rows ONLY after we finish with operation, and ONLY we will draw visible Cells on screen. After you finish with adding rows, ALLWAYS call EndUpdate.

Here you can see example how to add 100000 rows and to place Value in each Cell:

GridView.BeginUpdate;
for i := 0 to 100000 do
begin
GridView1.Cell[1, i].AsBoolean := False;
GridView1.Cell[2, i].AsString := Names[Random(1000)] + ' ' + Names[Random(1000)];
GridView1.Cell[3, i].AsInteger := Random(2);
GridView1.Cell[4, i].AsDateTime := Today-Random(500);
GridView1.Cell[5, i].AsFloat := Random(2000);
GridView1.Cell[6, i].AsInteger := Random(101);
GridView1.Cell[7, i].AsString := Cards[Random(4)];
GridView1.Cell[8, i].AsInteger := Random(6);
GridView1.Cell[9, i].AsInteger := Random(2);
end; GridView.EndUpdate;

When you don't need BeginUpdate and EndUpdate methods?

If you work with one rows or up to 1000 rows, you don't need to use BeginUpdate and EndUpdate, because speed will be almost same.

Chosing Column Type

In TTextualColumn you can put any kind of information: Text, Numbers, Date. Also, you can calculate SUM, COUNT, AVERAGE, MAX, MIN formulas in footer of TTextualColumn.

But, storing numbers or dates inside TTextualColumn is slower than storing number inside TNumericColumn or date inside TDateColumn.

So, if you plan to have column with only numbers, chose TNumericColumn. This column draw, change, sort and calculate formulas for numbers much faster than TTextualColumn do. This is because Double is native type for this column. TTextualColumn need to do lots of conversion (FloatToStr, StrToFloat...) to sort numbers or to display it.

 

 


 
Copyright © BergSoftware 1996 - 2009. All rights reserved.Contact Us.