Click here to Skip to main content
Click here to Skip to main content

The Ultimate Grid Datasources

, 24 Aug 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
An introduction to using custom datasources with the Ultimate Grid

Visit the Ultimate Grid main page for an overview and configuration guide to the Ultimate Grid library.

Contents

Introduction

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 CUGDataSource.

Up to 64000 CUGDataSource derived classes may be attached to each CUGCtrl class.

Why Use a Custom DataSource?

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.

Serialization

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.

Pre-built DataSources and Examples

Many pre-defined CUGDataSource objects are included with Ultimate Grid:

ADO CADOImpDatasource

This datasource wraps the Active Data Objects interface, which in turn layers OLE DB.

Files:
DataSources\ADO\ADOImpDatasource.cpp ADOImpDatasource.h

Samples:
DataSources\ADO\ADODataSource\
DataSources\ADO\ADO Sample\

Array CUGCBArrayDataSource

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.

Files:
DataSources\Array\UGCBADSC.cpp UGCBADSC.h

Sample:
DataSources\Array\Dumper3\

DAO CUGDAODataSource

The DAO datasource maintains member CDaoDatabase, CDaoTableDef, CDaoQueryDef, CDaoRecordset, and 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.

Files:
DataSources\DAO\Ugdao.cpp Ugdao.h

Samples:
DataSources\DAO\DAO Sorting\
DataSources\DAO\MyAccess\

Additional:
DataSources\DAO\dao.htm
Delimited CUG_Delimitted

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).

Files:
DataSources\Delimited\UGdelim.cpp UGdelim.h

Sample:
DataSources\Delimited\Example\

Additional:
DataSources\delimited\ReadME.txt

Html CUG_HTML_DataSource

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.

Files:
DataSources\Html\UGHTML.cpp UGHTML.h

Sample:
DataSources\Html\htmlexam\

ODBC CUGODBCDatasource

The CUGODBCDatasource class includes a CUGRecordset class derived from CRecordset that uses the ODBC API directly to enable dynamic identification of table columns, types, etc.

Files:
DataSources\ODBC\ugrecset.cpp ugrecset.h UGODBC.CPP UGODBC.H

Samples:
DataSources\ODBC\odbcexam\
DataSources\ODBC\odbcexm2\

OLE DB CUG_OLEDB_DataSource

The OLE DB datasource and column binding classes can dynamically access database result sets through the OLE DB data interfaces.

Files:
DataSources\OleDB\binds.cpp binds.h ugoledb.cpp ugoledb.h

Sample:
DataSources\OleDB\Example\

XML CXMLParser

The XML datasource atypical of the classes described here, as is not derived from CUGDataSource. The 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.

Files:
DataSources\XML\COXParser\*.*
DataSources\XML\XMLParser.cpp XMLParser.h

Sample:
DataSources\XML\XMLSample\

Creating Custom CUGDataSource Classes

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.

History

Initial CodeProject release August 2007.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

The Ultimate Toolbox
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.
 
Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
Group type: Organisation

387 members


Comments and Discussions

 
Questionhow to force redraw of cell if visible after external datasource has updated [modified] Pinmembergfanini@tiscalinet.it7-Aug-13 5:53 
BugCannot download the source code for this project PinmemberMember 824623723-Nov-12 4:18 
QuestionHow to make ID column not show and insert can generate a new ID value Pinmembermaplewang10-Jul-12 21:31 
GeneralMy vote of 5 Pinmembermaplewang10-Jul-12 21:25 
QuestionHow to set top header rows number and join header cells in DataSource? Pinmembericeway16-Nov-09 17:39 
AnswerRe: How to set top header rows number and join header cells in DataSource? PineditorTim Deveaux17-Nov-09 8:48 
GeneralCUGDatasource::Browse crash [modified] PinmemberRymka5-Nov-09 3:10 
GeneralDemo program "db7" (odbcexam2) crashes PinmemberJRCooper27-Oct-09 9:14 
QuestionHow to use a dynamical data source with a known row count Pinmembericeway26-Oct-09 18:17 
AnswerRe: How to use a dynamical data source with a known row count PineditorTim Deveaux27-Oct-09 8:12 
GeneralCursors: clientside / serverside Pinmembermssg13-Feb-09 2:27 
QuestionUsing .mdf files in Ultimate Grid? Pinmembervahid_m_20089-Dec-08 23:54 
AnswerRe: Using .mdf files in Ultimate Grid? PineditorTim Deveaux10-Dec-08 6:15 
GeneralRe: Using .mdf files in Ultimate Grid? Pinmembervahid_m_200815-Dec-08 23:48 
GeneralRe: Using .mdf files in Ultimate Grid? PineditorTim Deveaux17-Dec-08 6:20 
GeneralProblem with the Datasource based on SQL Server2000 Pinmemberjiangbing30-Nov-08 1:46 
GeneralRe: Problem with the Datasource based on SQL Server2000 PineditorTim Deveaux30-Nov-08 7:48 
GeneralRe: Problem with the Datasource based on SQL Server2000 Pinmemberjiangbing30-Nov-08 15:07 
GeneralRe: Problem with the Datasource based on SQL Server2000 PineditorTim Deveaux2-Dec-08 9:24 
GeneralRe: Problem with the Datasource based on SQL Server2000 Pinmemberjiangbing4-Dec-08 3:18 
GeneralRe: Problem with the Datasource based on SQL Server2000 PineditorTim Deveaux4-Dec-08 6:40 
QuestionDatasource based on Oracle OCI Pinmembermgampi29-Aug-07 1:32 
AnswerRe: Datasource based on Oracle OCI Pinmemberpengdingfu26-Nov-07 17:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 25 Aug 2007
Article Copyright 2007 by The Ultimate Toolbox
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid