Workaround: use custom context menu
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
MyPivotGridContextMenu menu = new MyPivotGridContextMenu(this.radPivotGrid1.PivotGridElement);
this.radPivotGrid1.PivotGridElement.ContextMenu = menu;
}
private void Form1_Load(object sender, EventArgs e)
{
this.productsTableAdapter.Fill(this.nwindDataSet.Products);
LocalDataSourceProvider dataProvider = new LocalDataSourceProvider();
dataProvider.ItemsSource = nwindDataSet.Products;
dataProvider.BeginInit();
dataProvider.RowGroupDescriptions.Add(new PropertyGroupDescription() { PropertyName = "CategoryID", GroupComparer = new GroupNameComparer() });
dataProvider.RowGroupDescriptions.Add(new PropertyGroupDescription() { PropertyName = "ProductName", GroupComparer = new GroupNameComparer() });
dataProvider.ColumnGroupDescriptions.Add(new PropertyGroupDescription() { PropertyName = "ProductID" });
dataProvider.AggregateDescriptions.Add(new PropertyAggregateDescription() { PropertyName = "UnitPrice", AggregateFunction = AggregateFunctions.Sum });
dataProvider.EndInit();
this.radPivotGrid1.DataProvider = dataProvider;
}
}
public class MyPivotGridContextMenu : PivotGridContextMenu
{
public MyPivotGridContextMenu(RadPivotGridElement pivotGridElement)
: base(pivotGridElement)
{ }
protected override void OnCollapseAllMenuItemClick(object sender, EventArgs e)
{
PivotGroupElement groupElement = this.Context as PivotGroupElement;
if (groupElement != null)
{
RadPivotGridElement pivotGridElement = this.GetType().BaseType
.GetField("pivotGridElement", BindingFlags.Instance | BindingFlags.NonPublic)
.GetValue(this) as RadPivotGridElement;
pivotGridElement.SuspendLayout(true);
if (groupElement.Data.Axis == PivotAxis.Rows)
{
foreach (PivotGroupNode node in pivotGridElement.GetRowGroups())
{
node.Expanded = false;
}
}
else
{
foreach (PivotGroupNode node in pivotGridElement.GetColumnGroups())
{
node.Expanded = false;
}
}
pivotGridElement.ResumeLayout(true, true);
pivotGridElement.UpdateAfterExpandCollapse();
}
}
}