Visit the Ultimate Grid main page for an overview and configuration guide to the Ultimate Grid library.
One of the nice design features of the Ultimate Grid is the abstraction of the data layer from the presentation layer through the use of a base data source class. The
CUGDataSource class abstracts all functions relating to a data source. This design allows for a high degree of code reuse, and allows tremendous flexibility in Ultimate Grid's implementation, allowing many different types of data sources to be used in combination, or interchangeably, without the need to re-code the inner workings of the grid or your application.
Most developers will begin with the default - the 'built in' "Memory Manager" (
CUGMem) data source class, which allows for cell objects to be stored in the grid for display, and retrieved for manipulation.
CUGMem is derived from
Up to 64000
CUGDataSource derived classes may be attached to each
Dynamic Loading of Cell Information
You may wish to use a derived
CUGDataSource class for loading cell information dynamically. Dynamic loading of cell information greatly improves performance for large tables, reduces memory requirements, and allows the grid to be displayed on-screen instantaneously.
You may have a file which contains data with mark up to display and edit - XML would be a good example.
Incorporating Data Access APIs
Many Microsoft and 3rd party database implementations supply C/C++ interfaces to directly invoke SQL queries and access the result sets returned. This can allow for fully dynamic identification of columns, column types, and an efficient dynamic display of both static and dynamic result sets.
CUGDataSource objects are included with Ultimate Grid:
This datasource wraps the Active Data Objects interface, which in turn layers OLE DB.
An example of using a simple byte array as a datasource - the Dumper sample loads a file as a binary array and displays a hex/text dump.
The DAO datasource maintains member
CDaoFieldInfo objects to allow for dynamic loading of Microsoft Access database query result sets.
Support for transactions is available.
Implements sorting and find next (FindDialog) functionality.
An example of a serializable datasource, the
CUG_Delimited class can read CSV files etc. The delimiter character can be specified. Derived from
CUGMem (the default memory based datasource for the grid).
This data source handles importing simple HTML tables. It will skip over embedded tables to completely import the table. You can decided which of the outer most tables to import by passing a table number to the Open function.
CUGODBCDatasource class includes a
CUGRecordset class derived from
CRecordset that uses the ODBC API directly to enable dynamic identification of table columns, types, etc.
DataSources\ODBC\ugrecset.cpp ugrecset.h UGODBC.CPP UGODBC.H
The OLE DB datasource and column binding classes can dynamically access database result sets through the OLE DB data interfaces.
DataSources\OleDB\binds.cpp binds.h ugoledb.cpp ugoledb.h
The XML datasource atypical of the classes described here, as is not derived from
CXMLParser class maintains a pointer to a grid object which it can populate with data and cell properties gleaned from an XML file, but the grid itself uses the default memory datasource.
This class has been updated for better rendering of Microsoft Excel xml attributes.
Probably the most common need for a custom datasource is when dealing with a large amount of external data (for which you already have an interface) that can retrieve data based on a col and row vector, obviating the overhead that would be required in duplicating data items by preloading them through the
SetCell interface of the grid.
Custom data sources can be engineered with as little as one virtual override of the
GetCell() function. Depending upon your requirements, you may also wish to provide the data source class with the ability to write information back to the data source through the
SetCell() function. Your data source class can also be responsible for reordering the data source based upon indices, calculating the total number of rows, calculating the number columns, determining the column headings, etc. You may provide as much or as little functionality as you require in your custom data source classes.
In a fully developed data source class special functions such as
SetGridFromDataSource() can be added to allow the grid to automatically ask the data source for information on column titles, column types, formatting, etc., and automatically set the default grid and column cell objects with this information.
Once you have a
CUGDatasource derived class in place, simply declare an instance in and call the grid's
AddDatasource method to add it to the grid's array of known datasources. To set it as the current datasource for the grid, call
SetDefDatasource with the index returned from
AddDatasource. The grid will then query your
GetCell method when drawing data.
For more on creating and using datasources with the Ultimate Grid, refer to the tutorials and class references in the compiled CHM help documentation.
Initial CodeProject release August 2007.