Data Dynamics Analysis Online Help Support Forum
Add a Hierarchy
See Also
Data Dynamics Analysis Developer Guide > Developer How To > Modify a Schema Using the SchemaBuilder API > Add a Hierarchy

Glossary Item Box

Hierarchies create relationships between non-numeric fields that you pull from a data source and display them in different levels and allow users to navigate them. Adding a field to a hierarchy adds the field to the Attributes dimension.


Click to EnlargeClick to Enlarge

To add a hierarchy

These steps assume that you have already loaded an existing schema and added a query field.

  1. In the code view of the form containing your PivotView control, add code to the Button1 Click event below the previously added code.
  2. Add code like the following to the Click event to add a hierarchy to your schema.

    ShowTo write the code in Visual Basic.NET

    Visual Basic.NET code. Paste INSIDE the Button Click event below the previously added code. Copy Code
    'Create a Category ID attribute.
    Dim attribute As New AttributeBuilder("Category ID")
    attribute.SetExpression(Of String)("=Fields!CategoryID.Value")
    
    'Add the Category ID attribute to an existing hierarchy.
    
    'Get the Products dimension.
    Dim attributeDimension As AttributesDimBuilder
    attributeDimension = myNewSchema.Dimensions("Products")
    
    'Add the attribute to an existing hierarchy.
    Dim hi As HierarchyBuilder
    hi = attributeDimension.Fields("Product Categories")
    hi.AddLevel(New LevelBuilder("Category ID") _
        .SetExpression("=Fields!CategoryID.Value"))
    
    'Add the attribute within the hierarchy to the Attributes list.
    attributeDimension.AddField(attribute)
    

    ShowTo write the code in C#

    C# code. Paste INSIDE the Button Click event below the previously added code. Copy Code
    //Create a Category ID attribute. 
    AttributeBuilder attribute = new AttributeBuilder("Category ID"); 
    attribute.SetExpression<string>("=Fields!CategoryID.Value"); 
        
    //Add the Category ID attribute to an existing hierarchy. 
        
    //Get the Products dimension. 
    AttributesDimBuilder attributeDimension = default(AttributesDimBuilder); 
    attributeDimension = (AttributesDimBuilder)myNewSchema.Dimensions["Products"]; 
        
    //Add the attribute to an existing hierarchy. 
    HierarchyBuilder hi = default(HierarchyBuilder); 
    hi = (HierarchyBuilder)attributeDimension.Fields["Product Categories"]; 
    hi.AddLevel(new LevelBuilder("Category ID").SetExpression("=Fields!CategoryID.Value")); 
        
    //Add the attribute within the hierarchy to the Attributes list. 
    attributeDimension.AddField(attribute);
    
  3. To save the modified schema, see Modify a Schema Using the SchemaBuilder API.

See Also

©2009. GrapeCity, inc. All rights reserved.