Binding my custom control to a datasource at runtime

Binding my custom control to a datasource at runtime

Post by Jos Koeni » Fri, 15 Jun 2001 19:30:18



Hi,

I created a custom control, which is bindable to a datasource. This works
okay if I bind it to the datasource at designtime (Setting the datasource
property to 'ADODC1' for example), but I can't bind it at runtime, like
this:

MyObject.Datasource = AdoDC1

I get the error 'Method or Data member not found', and VB selects the text
datasource.
But the property datasource DOES exist! It's even in the dropdownlist, in
the codewindow!

When I try to bind a textbox the same way, it works fine (Text1.Datasource =
AdoDC1)

What am I doing wrong?

please help,

Jos

 
 
 

Binding my custom control to a datasource at runtime

Post by Alexander Shirsho » Fri, 15 Jun 2001 21:26:09


Jos,

Try this:
Set MyObject.Datasource = AdoDC1

--
HTH,
Alexander Shirshov, MCSD


Quote:> Hi,

> I created a custom control, which is bindable to a datasource. This works
> okay if I bind it to the datasource at designtime (Setting the datasource
> property to 'ADODC1' for example), but I can't bind it at runtime, like
> this:

> MyObject.Datasource = AdoDC1

> I get the error 'Method or Data member not found', and VB selects the text
> datasource.
> But the property datasource DOES exist! It's even in the dropdownlist, in
> the codewindow!

> When I try to bind a textbox the same way, it works fine (Text1.Datasource
=
> AdoDC1)

> What am I doing wrong?

> please help,

> Jos


 
 
 

Binding my custom control to a datasource at runtime

Post by Jos Koeni » Fri, 15 Jun 2001 22:38:08


Sorry, that's exactly what I did (forgot to put the 'Set' in the email), but
it doesn't work

thanks anyway



Quote:> Jos,

> Try this:
> Set MyObject.Datasource = AdoDC1

> --
> HTH,
> Alexander Shirshov, MCSD

 
 
 

Binding my custom control to a datasource at runtime

Post by <reyg.. » Sat, 16 Jun 2001 04:30:10


You did not mention what type of custom control you created i.e.
DataGrid,MSFlexgrid,etc..
The error message you mentioned happens when ADODC1 RecordSource property
does not match with the Object.DataSource that you are trying to bind it
with.  

Ex.
Design Time
The ff. codes will automatically populate the DataGrid control(for
example) with data from Table1.
ADODC1.RecordSource = Table1
Datagrid.DataSource = ADODC1

If your intended output control is designed to show data from Table2 or
contains other data that does not belong to Table1, then you will get an
error. The reason the datasource property was highlighted is because your
custom control is trying to get data that does not match ADODC1
RecordSource property.

In short: at Run Time
Set ADODC1.RecordSource = ""
Set ADODC1.RecordSource = "the table or SQL statement you want to use"
Datagrid.DataSource = ADODC1

HTH

--
Posted via CNET Help.com
http://www.help.com/

 
 
 

Binding my custom control to a datasource at runtime

Post by Jos Koeni » Sat, 16 Jun 2001 15:30:29


Stil doesn't work. Please read my comments below:



Quote:> You did not mention what type of custom control you created i.e.
> DataGrid,MSFlexgrid,etc..

It is a self made user control (.ctl), with a just couple of textboxes.

Quote:> The error message you mentioned happens when ADODC1 RecordSource property
> does not match with the Object.DataSource that you are trying to bind it
> with.

That's not it. Example:
I created a AdoDC1 object, which connects to a SQL query in a database
"SELECT * FROM Companies ORDER BY Name"

If at designtime I set MyObject 's property DataSource to AdoDC1, and I set
the DataBindings correctly (I bind the 'Name' field of my control to the ,
it works fine.

If in my code I try to connect the control to the exact same AdoDC1 object
it doesn't work. Like this:

Set MyObject.DataSource=AdoDC1

And then I'll get the error I  mentioned. (Method or datamember not found)

I hope anyone can help me out,

Jos.

Quote:> Ex.
> Design Time
> The ff. codes will automatically populate the DataGrid control(for
> example) with data from Table1.
> ADODC1.RecordSource = Table1
> Datagrid.DataSource = ADODC1

> If your intended output control is designed to show data from Table2 or
> contains other data that does not belong to Table1, then you will get an
> error. The reason the datasource property was highlighted is because your
> custom control is trying to get data that does not match ADODC1
> RecordSource property.

> In short: at Run Time
> Set ADODC1.RecordSource = ""
> Set ADODC1.RecordSource = "the table or SQL statement you want to use"
> Datagrid.DataSource = ADODC1

> HTH

 
 
 

Binding my custom control to a datasource at runtime

Post by Jos Koeni » Sat, 16 Jun 2001 17:39:22


Well, finally I managed to get it working. I didn't change any code, but
after playing with the references a bit (Which ended in adding Microsoft
Data Source Interfaces), and compiling the usercontrol to an ocx, it worked.
 
 
 

1. CanU: Bind Grid1.DataSource = runtime ado recordset?

I've seen code snippets that attemp to bind a Grid's DataSource to a
runtime ADODB.Recordset  (much like the following):

Dim rs As New ADODB.Recordset
rs.open......
Set Grid1.DataSource = rs

Whenever I try this (Whether with DBGrid, MSFlexGrid, or MSHFlexGrid)
all I get is errors (Object variable not set, ...does not support
bookmarking, etc).

Is this possible?
Is this possible using ADOR.Recordset (client side record sets).

Thanks in advance,
Daniel

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

2. SQL Error connecting with VB using ADO 2.7

3. Custom Control/Datasource Question

4. Image and text types.....stored procs

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

6. SQL Monitor

7. Binding of 3rd party Database Controls to Datasource in VC++ 4.2

8. What constitutes a client access?

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

10. Setting ADODC control's datasource at runtime

11. HELP! ADODC bound to VB Custom Control - Updating

12. Changing the recordsource to a data component for a bound control at runtime