ComponentOne True DataControl 8.0
Events in Creating Recordset at Run Time

True DataControl creates its recordset on startup and each time the Refresh method is called, by firing three events that allow full programmatic control over this process: WillOpenData, OpenData and OpenDataComplete.

The WillOpenData event occurs before recordset creation. This event gives the developer an opportunity to change True DataControl collections, such as Fields, before they are used to create the recordset. Use the Fields property to access the Fields collection. Any change to True DataControl fields and some other collections can obviously effect the resulting recordset. That is why True DataControl collections can’t be modified arbitrarily from code, surely not while they are used to create a recordset. You are allowed to do so in WillOpenData, so the recordset created will be based on the modified collection settings. True DataControl collections cannot be modified in any event other than WillOpenData. Modifying True DataControl collections from code outside of events causes refresh to occur. For more information, see Modifying True DataControl collections from code.

The OpenData event occurs immediately after WillOpenData. The main purpose of this event is to allow the developer to set SourceRecordset in code to an arbitrary ADO recordset (DataMember/DataSource properties also can be set in OpenData). If this is done, True DataControl ignores the data source property settings, does not create SourceRecordset, it uses the one supplied by the developer.

Another useful feature of the OpenData event is that it allows you to modify SourceRecordset while still relying on True DataControl for its creation. This is necessary because the True DataControl data source properties do not include all recordset properties. Some important properties, such as Filter and Sort, cannot be set at design time. The OpenData event allows you to modify the SourceRecordset created by True DataControl, to fine-tune it for your needs. For example, the following code ensures that the First field sorts the recordset, while the recordset itself is created automatically by True DataControl from data source property settings:

Example Title
Copy Code
Private Sub TData1_OpenData()

   TData1.SourceRecordset.Sort = "First"

End Sub

This twofold functionality of SourceRecordset in OpenData is achieved by the following simple rules:

The OpenDataComplete event occurs after the OpenData event, when True DataControl has created the recordset (if necessary), so all actions involved in creating the recordset have been completed. This is the place to put code, depending on the resulting recordset. For example, you can save a reference to the True DataControl SourceRecordset or Recordset property in a variable here.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback