Dapfor home  

Introduction to the grids. Existing solutions.

In this article we will give description of existing solutions to present data in grids. There are the next kinds of grids:


Grids working in the real mode (without virtualization)
Grids with virtualization
Data-table like grids
Grids with the data binding


Grids working in the real mode (without virtualization)

These grids have an internal data structure, which is presented by a list of rows. Each row is presented by a list of items that are shown in the cells of the grid. Generally, an access to these cells happens by referencing the row and column. The interface may look like:

grid.Rows[index][column] = "something";

For example, the CListCtrl of the MFC library offers the next syntax:

LVITEM lvi;                     //Corresponds to a row in the grid
lvi.iSubItem = 1;               //The column index
lvi.pszText = _T("something");
grid.SetItem(&lvi);

where lvi corresponds to the row, and lvi.iSubItem to the column. As you see, this looks like a bi-dimensional array, where all data is stored as formatted strings. When you call grid.SetItem(...), behind the grid calls Invalidate() with the dimensions of the cell, and at reception WM_PAINT it draws the string "something" in the right position. This behaviour is transparent for the programmer.

There are not a lot of advantages of this mode. The single advantage is that it is easy.

Limitations of this design:

Grids with virtualization

The main idea of this approach is based on peculiarity of the Windows operation system where the painting mechanism is separated on two parts. If you want to design something somewhere, firstly you should call the Invalidate() function of the CWnd with specified bounds. Windows cumulates rectangles, and then it fires WM_PAINT message. By receiving this message, the control has a possibility to draw text, lines, etc in the requested bounds. All grids use directly or indirectly this mechanism. In case of virtualization the grid does not keep formatted data, but ask it at painting time.

Advantages:

Main problems:

Data-table like grids

The next step to simplify the programmer's life is the data-table like grids. The main approach is to create an intermediate level, presented by the data table. Such table contains bi-dimensional array (rows & columns) which can be bound to the grid. The main difference between the real-mode and table-like grids is that the table contains an array of non-formatted values (long, double, etc... but not formatted strings). The presentation happens through formats that transform these values to strings. The one or multiple grids can listen for notifications from the same table and automatically update the visible content.

Access to the data looks like:

table[row][column] = my_value

Advantages:

Difficulties:

Grids with the data binding

This is a real revolution in the grid design. This permits to greatly simplify the application by separating the business data from the presentation. Data-table approach limits the data organization and adds an intermediate level between business data and its presentation. What is new in this mechanism? Each object may have some data and functions that get or manipulate this data. Such object may be directly inserted into the grid and the functions of this object can give information for cells. That means that the functions may correspond to the columns. The mechanism that permits to retrieve data from the object by calling its functions is called data binding. If the object offers a notification mechanism, and the grid implements it, then the programming becomes very easy. Thanks to it you will have a clear business model and after the binding you can forget that your object is presented somewhere. If you call set-functions of your object, each grid that is bound to your data will update, sort, filter, etc... your data. You don't need to worry where it is presented.

Advantages:

General problems:

We offer the solution, which is based on the data binding thread-safe mechanism. This means, that the grid can receive data updates from any thread and performs the synchronization itself. Moreover, our solution is not only thread-safe, but also dead-lock free because the data updating doesn't locks the calling thread.


Copyright Dapfor 2007-2009
Generated on Sat Jan 30 15:01:23 2010 for MFCGrid by doxygen 1.5.5