Testing the MyData Component

See Also

In the previous topics, we created an ActiveX DLL containing two classes, MyOSPObject and MyDataSource. In this topic we'll use the MyDataComponent object as a data source for the form that we created in an earlier topic.

Note   This topic is part of a series that walks you through creating sample data source components. It begins with the topic Creating Data Sources.

To test the MyData control

  1. Select Project 1 (DataSourceTest.vbp) in the Project Explorer.

  2. Select References from the Project menu to open the References dialog. Add a reference to MyDataComponent.

  3. Add a reference to the Microsoft Data Adapter Library. The Data Adapter object acts as an intermediate layer between OLE DB and OSP.

  4. Double-click Form1 in the Project Explorer to open its designer.

  5. Select DataGrid in the ToolBox and add a second DataGrid to Form1. You don't need to set any properties for DataGrid2.

  6. Double-click Form1 to open its code window. In the Object box, select (General). In the Procedure box, select (Declarations) to position yourself at the top of the code module. Add the following code:
    Option Explicit
    Dim da As New DataAdapter
    Dim ds As New MyDataSource
    
  7. In the Object box, select Form. In the Procedure box, select the Load event. Add the following code to the Form_Load event procedure to initialize the MyDataComponent object and assign it to the controls:
    Private Sub Form_Load()
       ' Set the Object property of the Data Adapter 
       ' to the MyDataSource object
       Set da.Object = ds
       
       ' Set the DataMember property
       DataGrid2.DataMember = App.Path & "\Customer.txt"
       ' Set the DataSource to the DataAdapter
       Set DataGrid2.DataSource = da
    End Sub
    

    Note   The above code assumes that the Customer.txt file is located in the same directory as your application. If you have the Customer.txt file in a different location, change the path accordingly. A copy of the Customer.txt file is included with the AXData sample application.

  8. Select Start from the Run menu to run the project.

    Notice that the second DataGrid contains the same data as the first; like the first, you can edit data in the second grid and the changes will be saved. The big difference between the two is that the first DataGrid is bound to a database, but the second DataGrid isn't — it's bound to a text file through the OLE DB Simple Provider interface.

That does it for the data sources example. Of course, you could easily expand on this. For example, you might add methods to the MyOSPObject class to navigate through the records, or perhaps methods that validate content or formatting for a particular field. You can take it as far as you want.

Step by Step

This topic is part of a series that walks you through creating sample ActiveX data sources.

To See
Go to the next step Data Sources Recap
Start from the beginning Creating Data Sources