Click to See Complete Forum and Search --> : How to use DataSource property inside of my own ActiveX Control?


Bon La Lay
August 5th, 2001, 10:49 PM
Hi all, thanks for all of your helps. Now I have a problem about how to use the DataSource property
in my ActiveX Control. As you know if you want to bind a control to a data source, use the Procedure
Attributes dialog box to bind one property as data bound. Then when you use this control, VB will
add Datasource and DataField properties to your control. That is running fine. But inside my control
how can I use the data source property that will be auto added by VB when you use it.

To make it clear, I suppose there is a textbox and a commandbutton on my Usercontrol. Then I have a
property named "uText". I assign the data bound property to it by using the Procedure Attributes
dialog.

After doing that, means the uText will bound the DataField together with affecting the contents of
the real TextBox on my usercontrol.

And now, when you click the CommandButton on the usercontrol, I want to fire the AddNew method of
the individual DataSource( Data Source can be Recordset or Data Environment, no matter which one
you choose, it has the .AddNew method ). Then the problem comes out:

UserControl hasn't DataSource property! How I can fire any methods of the DataSource object inside
of the whole usercontrol. Not when you using it.

Below has the code:


option Explicit

public property get uText() as string
uText = Text1.Text
End property

public property let uText(byval Value as string)
Text1.Text = Value
PropertyChanged "uText"
End property

private Sub Command1_Click()

' I cannot use this code, how to make it?

' *****************************
UserControl.DataSource.AddNew
' *****************************

End Sub





Any suggestions will be highly appreciated!

//-----------------------------------------\\
Where there's a wire , there's a way
\\-----------------------------------------//