Problem setting the datasource property of a MS FlexGrid Control

Problem setting the datasource property of a MS FlexGrid Control

Post by Phillip Rhode » Tue, 19 Jun 2001 11:44:41



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

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" );
 m_Adodc.Refresh();

 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
IDispatch*
blows up when it executes.

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

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

 
 
 

Problem setting the datasource property of a MS FlexGrid Control

Post by Sebastian Broghamme » Tue, 19 Jun 2001 15:49:16


Hi Phillip,

Quote:

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

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

SetDataSource needs an IDispatch which inerence also _Recordset (this is a
ADO
interface). I don't know what CAdodc is, but probably it has no _Recordset
interface.

So check how you can get the _Recordset interface and do an that interface
an QueryInterface
for IDispatch and give the result to SetDataSource.

This should work

Greetings

Sebastian

 
 
 

1. Make DataSource Property in my Class to connect with FlexGrid

Hi people !!
I'd like to make a Class or ActiveX with a DataSource property IN DAO (not
ADO) to connect this to a FlexGrid.
I tryed to do this:
The same code but with ADO Works \8-( !!

In my class
    I put DataSourceBehavior = vbDatasource
    I declare a Private rsdao as DAO.Recordset
    In procedure
        Class_GetDataMember
            Set Data = rsdao
        end ...
    then I make a
        property Get Recordset() as DAO.Recordset
              Set Recordset = rsDAORec
        end ...

In a Form
    dim datNames as New Class1

    Private Sub Form_Load()
      Dim db As Database
      Set db = OpenDatabase("c:\ ....mdb")
      Set datNames.Recordset = db.OpenRecordset("Select * From ....")
      Set MsFlexGrd1.Datasource =  datNames
    End Sub

Do You know what's wrong ? or if I can do that with other control similar
than FlexGrid ?
I'm new and sorry me if my english is not good ;-)

--
Leonardo Onieva

2. replication b/w two servers in workgroup

3. Tab control/FlexGrid control problem

4. Can't connect

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

6. ADO connection string with variables

7. DataSource Property of Grid Controls

8. DataSource property in user created control

9. ADODC control - DataSource Property back to nothing

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

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