To reproduce:
Add a RadPivotGrid and a few columns, select one column and show the PrintingDialog. Select "Print Selection Only", exception will occur.
Workaround:
Use the following print style -
public class MyPrintStyle : PivotGridPrintStyle
{
private Func<Rectangle, SizeF> getScaleFactors;
private Func<int, Rectangle, float, int> getStartColumn;
private Func<int, Rectangle, float, int> getEndColumn;
private Func<int, Rectangle, float, int> getStartRow;
private Func<int, Rectangle, float, int> getEndRow;
private List<AggregateDescriptionBase> aggregates;
private List<int> columnWidths;
private List<int> rowHeights;
private Type baseType;
private BindingFlags flags;
public override void Initialize()
{
base.Initialize();
this.baseType = typeof(PivotGridPrintStyle);
this.flags = BindingFlags.NonPublic | BindingFlags.Instance;
this.getScaleFactors = this.GetFuncFromParent<Rectangle, SizeF>("GetScaleFactors");
this.getStartColumn = this.GetFuncFromParent<int, Rectangle, float, int>("GetStartColumn");
this.getEndColumn = this.GetFuncFromParent<int, Rectangle, float, int>("GetEndColumn");
this.getStartRow = this.GetFuncFromParent<int, Rectangle, float, int>("GetStartRow");
this.getEndRow = this.GetFuncFromParent<int, Rectangle, float, int>("GetEndRow");
this.aggregates = GetField<List<AggregateDescriptionBase>>("aggregates");
this.columnWidths = GetField<List<int>>("columnWidths");
this.rowHeights = GetField<List<int>>("rowHeights");
}
private T GetField<T>(string name)
{
return (T)this.baseType.GetField(name, flags).GetValue(this);
}
private Func<T, TResult> GetFuncFromParent<T, TResult>(string method)
{
MethodInfo getScaleFactor = baseType.GetMethod(method, flags);
var func = (Func<T, TResult>)Delegate.CreateDelegate(typeof(Func<T, TResult>), this, getScaleFactor);
return func;
}
private Func<T1, T2, T3, TResult> GetFuncFromParent<T1, T2, T3, TResult>(string method)
{
MethodInfo getScaleFactor = baseType.GetMethod(method, flags);
var func = (Func<T1, T2, T3, TResult>)Delegate.CreateDelegate(typeof(Func<T1, T2, T3, TResult>), this, getScaleFactor);
return func;
}
public override void DrawPage(Rectangle drawArea, Graphics graphics, int pageNumber)
{
int x = drawArea.X;
int y = drawArea.Y;
SizeF scale = this.getScaleFactors(drawArea);
int startColumn = this.getStartColumn(pageNumber, drawArea, scale.Width);
int endColumn = this.getEndColumn(startColumn, drawArea, scale.Width);
int startRow = this.getStartRow(pageNumber, drawArea, scale.Height);
int endRow = this.getEndRow(startRow, drawArea, scale.Height);
int aggregateIndex = 0;
for (int i = startRow; i <= endRow; i++)
{
x = drawArea.X;
int maxHeight = 0;
for (int j = startColumn; j <= endColumn; j++)
{
if (j == 0 && i == 0 && aggregateIndex < this.aggregates.Count)
{
while (aggregateIndex < this.aggregates.Count)
{
if (j >= this.columnWidths.Count || i >= this.rowHeights.Count)
{
break;
}
Rectangle aggregateElementRect = new Rectangle(x, y, this.columnWidths[j], this.rowHeights[i]);
RadPrintElement aggregatePrintElement = this.GetAggregateDescriptorCell(aggregateIndex++);
aggregatePrintElement.ScaleTransform = scale;
RectangleF aggregateTransformedRect = aggregatePrintElement.GetTransformedBounds(aggregateElementRect);
this.PrintElement(aggregatePrintElement, drawArea, aggregateElementRect, graphics);
x += (int)Math.Floor(aggregateTransformedRect.Width);
maxHeight = Math.Max(maxHeight, (int)Math.Floor(aggregateTransformedRect.Height));
if (aggregateIndex < this.aggregates.Count)
{
j++;
}
}
continue;
}
Rectangle elementRect = new Rectangle(x, y, this.columnWidths[j], this.rowHeights[i]);
RadPrintElement printElement = this.GetPrintElementForCell(i, j);
printElement.ScaleTransform = scale;
RectangleF transformedRect = printElement.GetTransformedBounds(elementRect);
this.PrintElement(printElement, drawArea, elementRect, graphics);
x += (int)Math.Floor(transformedRect.Width);
maxHeight = Math.Max(maxHeight, (int)Math.Floor(transformedRect.Height));
}
y += maxHeight;
}
}
}