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.
To add a hierarchy
These steps assume that you have already loaded an existing schema and added a query field.
- In the code view of the form containing your PivotView control, add code to the Button1 Click event below the previously added code.
- Add code like the following to the Click event to add a hierarchy to your schema.
To 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)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); - To save the modified schema, see Modify a Schema Using the SchemaBuilder API.
Hide All