65.9K
CodeProject is changing. Read more.
Home

DataGrid Control, EditText Control

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.64/5 (6 votes)

Feb 26, 2007

CPOL
viewsIcon

32469

downloadIcon

730

An article on yet another DataGrid Control

Screenshot - DataGridDemo.jpg

Introduction

This article presents a DataGrid control which is built with no MFC, no C++. It can be used in SDK or MFC Win32 applications.

Background

You can find various grid controls all over the Internet, some free and some not. The DataGrid control is attempt of realization of datagrid like msdatgrd.ocx from VB 6.0 with no ActiveX interface.

Using the code

To use this code you must define your datasource and register the following function:

1. int GetRecordCount( void )
2. int GetCountColumns( void )
3. char* GetColumnName( iIndexColumn )
4. char* GetValue( int iNumRow, int iNumField )
5. void SetValue( int iNumRow, int iNumField, char *szValue )

FARPROC fn;

fn=GetProcAddress( (HMODULE)hInstDLL, "DataGridFrameRegisterDataFunction" );
DataGridFrameRegisterDataFunction=(TDataGridFrameRegisterDataFunction)fn;
iRes=(*DataGridFrameRegisterDataFunction)(&ODBCGetRecordCount, 
&ODBCGetCountColumns,&ODBCGetColumnName,&ODBCGetValue, &ODBCSetValue);
if( iRes==0 )
{
...
}

If your datasource is insertable set bInsert=TRUE, if deletable set bDelete=TRUE, if updatable set bUpdate=TRUE. Then

fn=GetProcAddress( (HMODULE)hInstDLL, "DataGridSetDataAttribs" );
DataGridSetDataAttribs=(TDataGridSetDataAttribs)fn;
iRes=(*DataGridSetDataAttribs)( bInsert, bDelete, bUpdate );
if( iRes==0 )
{
...
}

If you want to catch events, you should define and register handlers.

fn=GetProcAddress( (HMODULE)hInstDLL, "DataGridSetEvents" );
DataGridSetEvents=(TDataGridSetEvents)fn;
iRes=(*DataGridSetEvents)( &OnHeadClick, &OnRowColChange, &OnAfterDelete, 
&OnBeforeColEdit );

See source code for details.