Hello,
Please excuse if I'm missing some basic concepts here. I'm attempting to something along the lines of this code snippet, which I found on another forum post:
HierarchyDescriptor<ProductData> dateTimeTodayDescriptor = new HierarchyDescriptor<ProductData>(pd => pd.Today);
dateTimeTodayDescriptor.AddLevel(pd => "Today", "All Dates");
dateTimeTodayDescriptor.AddLevel(pd => pd.Today.SemesterWithYear(), "Semesters");
dateTimeTodayDescriptor.AddLevel(pd => pd.Today.MonthShort(), "Months");
However, instead of a known class (in the example, "ProductData"), the ItemSource for my XamPivotGrid consists of a list of dynamic objects created using Infragistics.Olap.DynamicTypeBuilder. I have the property names of the object available in string variables. Any suggestions on how I might modify this example to handle my situation?
I've also tried a completely different approach such as:
// Create a HierarchyDescriptor for a property whose name is stored in col.ColumnName (I'd like it displayed using the string in col.Caption)...
var hier = new HierarchyDescriptor { SourcePropertyName = col.ColumnName, HierarchyName = col.Caption, HierarchyDisplayName = col.Caption, };// Then add a hierarchy level for the property...
HierarchyLevelDescriptor yLevel = new HierarchyLevelDescriptor
{
LevelName = "Years",
LevelExpressionPath = col.ColumnName
};
System.Linq.Expressions.Expression<Func<DateTime, int>> eY = date => date.Year;
yLevel.LevelExpression = eY;
hier.LevelDescriptors.Add(yLevel);
But this doesn't work at all (note that the "System.Linq.Expressions....." line is a total guess, since the LevelExpression property has no useful documentation whatsoever -- please take note that "gets or sets the LevelExpressions property" as the entire explanation doesn't tell us much).
Hopefully I've communicated what I'm trying to do here. Any suggestions of a way to get it done would be greatly appreciated!
And as a side note, what does the HierarchyDisplayName property actually do? It seems to have no effect -- the top of each Hierarchy shows in the XamPivotDataSelector as the ugly raw property name, not the nicer looking "caption" I'm trying to set it to. Can't find a way around that one either...
Thanks,
Bob
This behavior is caused because LevelExpressionPath currently does not support method calls. I'm not sure if it will work but you can try to expose a property of some complex type with single property which returns the method call value:
public class QuarterShort
private DateTime _dateValue;
public QuarterShort(DateTime dateValue)
this._dateValue = dateValue;
}
public string Value
get { return this._dateValue.QuarterShort(); }
Now with dynamic type builder define property of type QuarterShort and name col.ColumnName + "QuarterShort" and then your expression should be: col.ColumnName + "QuarterShort.Value"
Best regards,Plamen
Well, I have found one way that starts to work:
HierarchyLevelDescriptor yLevel = new HierarchyLevelDescriptor { LevelName = "Years", LevelExpressionPath = col.ColumnName + ".Year" }; hier.LevelDescriptors.Add(yLevel);But when I try to build the next level using a similar technique it fails (I can't drill in from Years to Quarters):
HierarchyLevelDescriptor qLevel = new HierarchyLevelDescriptor { LevelName = "Quarters", LevelExpressionPath = col.ColumnName + ".QuarterShort()" }; hier.LevelDescriptors.Add(qLevel);
I can't say I love having to build the LevelExpressionPath this way, writing code in a string literal, andit doesn't seem to work completely anyway (Why?). I'd think that using LevelExpression would be better, but again there's no documentation on how to use it.Help! :-)