Visual Basic Concepts
Scenarios For Using the Data Environment Designer
See Also
This section presents scenarios that illustrate how you can use the Data Environment designer. Among the features highlighted are creating a hierarchy, adding aggregates, grouping, and binding to a Hierarchical FlexGrid.
Creating a Relation Hierarchy Between a Customer and an Order Table
To create a relation hierarchy between a Customer and an Order table
- Create Command object, connected to the Northwind database.
- Select the Customers table as the Command object's source. Change the Command object name to "Customers."
- Create a child Command off the Customer Command object. Select the Orders table as the child's source. Change the child Command object's name to "Orders."
- Click the Relation tab, and then link the parent and child Command objects using their CustomerID fields.
To view the results, see "Binding Your Data Environment to a Hierarchical FlexGrid Control" later in this topic.
Adding an Aggregate to the Customer Command Object
To add an aggregate to the Customer Command object to obtain the SUM of the order amounts for all orders per customer
- Edit the Customer Command object's properties.
- Click the Aggregate tab, and then click Add.
- Name the aggregate "OrdersTotal."
- Select Sum as the function.
- Select the Aggregate On item "Orders".
- Select OrderID as the Field to Sum.
The OrdersTotal aggregate is added to the DataEnvironment object as a new Field object. At run time, the OrdersTotal aggregate will contain a calculated value for each customer.
To view the results, see "Binding Your Data Environment to a Hierarchical FlexGrid Control" later in this topic.
Grouping the Customer Command Object by State
To group the customer Command object by state
- Edit the Customer Command object's properties.
- Click the Grouping tab, and select Group Command Object.
- Name the grouping Command object "ByCountry."
- Select "Country" from the Fields in Command list, and then click > to move it into the Fields Used for Grouping list.
An additional Recordset object, ByCountry, is exposed on top of the Customers Command object. When binding to the Hierarchical FlexGrid, you should bind to the ByCountry Recordset, not to the Customers Command object.
To view the results, see "Binding Your Data Environment to a Hierarchical FlexGrid Control" later in this topic.
Adding an Aggregate to Count the Number of Customers per State
To add an aggregate to count the number of customers per state
- Edit the Customer Command object's properties.
- Click the Aggregates tab, and click Add.
- Name the aggregate "CustCount."
- Select Count as the function.
- Select the Aggregate On item "Grouping".
- Select CustID as the Field to Count.
Another field is added to the summary (grouping) Command object. This Field object contains a calculated value that counts the number of customers per state.
To view the results, see "Binding Your Data Environment to a Hierarchical FlexGrid Control" later in this topic.
Adding a Grand Total Aggregate to Count the Number of States with Customers
To add a Grand Total Aggregate to count the number of states with customers
- Edit the Customer Command object's properties.
- Click the Aggregates tab, and then click Add.
- Name the aggregate "NumStatesWithCustomers."
- Select Count as the function.
- Select GrandTotal as the Aggregate On item.
- Select the "State" as the Field.
- Name the Grand Total "CustomerGrandTotal."
An additional Recordset object, NumStatesWithCustomers, is exposed on top of the Customers Command object. This new object contains the number of states that have customers.
To view the results, see the following section.
Binding Your Data Environment to a Hierarchical FlexGrid Control
The following scenario is provided so you can view the results of the previous scenarios. See the Hierarchical FlexGrid Control for more information.
To bind your Data Environment to a Hierarchical FlexGrid control
- Once you have completed the previous Data Environment scenarios, drag an MSHFlexGrid control onto a Visual Basic form.
- From the Visual Basic property sheet, set the DataSource property to the DataEnvironment object that contains the Command object that you want to bind to the Hierarchical FlexGrid control. For example, specify DataEnvironment1.
- From the Visual Basic Properties window, set the DataMember property to a parent Command object in your Data Environment. Your data is now bound to a Hierarchical FlexGrid control.
- To view the data in the Hierarchical FlexGrid, select Start from the Run menu or press F5. The structure is retrieved and displays in the Hierarchical FlexGrid.