DataSource Property of Grid Controls

DataSource Property of Grid Controls

Post by Brett Aver » Fri, 26 Oct 2001 20:30:03

Anyone able to shed some light on the following  - running a test form with a
datagrid and an  msflexgrid and setting the datasource properties of both
controls as below. The datagrid display the fields from the ADO recordset but
not the msflexgrid. They both have a datasource property but attempting to set
the msflexgrid datasouce results in an error 'object variable or with block
variable not set'. Does the msflexgrid support being bound to a datasource or is
it a matter of filling it manually as per several code examples I have seen.

    Set DataGrid1.DataSource = datRs

    Set MSFlexGrid1.DataSource = datRs

Thanks for any help



1. Problem setting the datasource property of a MS FlexGrid Control

Hello all, I am wondering if somebody can help me with the following

I am writing a program, in C++, which needs to use an MS FlexGrid Control
( via the generated CMSFlexGrid wrapper class ) and the MS ADO Data Control.

I can create both the Data Control, and the FlexGrid Control fine. However,
I when I set the datasource property of the FlexGrid control to the Data
Control, it blows up.

Here is the code I am using....


m_Adodc.Create( NULL, NULL, CRect( 0, 0, 50, 50 ), this, 0);
 m_Adodc.SetConnectionString("DSN=Address;UID=sa;PWD=;" );
 m_Adodc.SetCursorLocation( adUseClient );
 m_Adodc.SetCursorType( adOpenStatic );
 m_Adodc.SetCommandType( adCmdText );
 m_Adodc.SetRecordSource( "SELECT * FROM Person" );

 IDispatch* pDispatch = 0;
 m_Adodc.GetControlUnknown()->QueryInterface( IID_IDispatch,
(void**)&pDispatch );

 if( pDispatch == NULL )
  AfxMessageBox( "Not an OLE Control!", MB_ICONERROR );

 m_FlexGrid.Create( NULL, WS_VISIBLE, CRect( 50, 50, 100, 100 ), this, 1);
 m_FlexGrid.SetDataSource( pDispatch );


This snippet is from the OnCreate method of a CView derived class, in an MFC
program.  m_Adodc is a member variable of type CAdodc ( the vis studio
generated wrapper class ), and m_FlexGrid is a member variable of type
CMSFlexGrid ( the other wrapper class ).

I have traced through the execution of this code, and after the call to
QueryInterface, pDispatch does appear to have a valid address ( at the
least, I can definitely say it's not null ).

However, the SetDataSource method, which takes a parameter of type
blows up when it executes.

If anybody can give me any clue on what's causing this, it would be much

Phillip Rhodes
Application Designer
Voice Data Solutions
919-571-4300 x225

I've changed my e-mail address to foil spammers.
Please remove the "no-spam" portion of
my domain name, to respond via e-mail.

2. transaction isolation level

3. txtfield().datasource property, without Adodc control

4. pgAdmin2 to be included in Dev-C++

5. DataSource property in user created control

6. Paradox 7 - urgent help required!

7. Image Datatype - binding datasource to a controls picture property

8. Archiving data within SQL Server 2000

9. ADODC control - DataSource Property back to nothing

10. Image Datatype - binding datasource to a controls picture property

11. Controls Inheriting Other Control's Properties

12. Binding an self-made Datasource to a Grid