This is a migrated thread and some comments may be shown as answers.

Calculated Field rename error

2 Answers 42 Views
PivotGrid and PivotFieldList
This is a migrated thread and some comments may be shown as answers.
Alex Dybenko
Top achievements
Rank 2
Alex Dybenko asked on 05 Mar 2018, 11:19 AM

Hi,

if I add calculated field like below:

https://docs.telerik.com/devtools/winforms/pivotgrid/calculated-fields

and then try to rename it using FieldList - More aggrerate options...

I got an exception:

System.InvalidOperationException: Operation is not valid due to the current state of the object.

   at Telerik.WinControls.UI.PivotGrid.Dialogs.AggregateOptionsDialog.get_SelectedQueryableAggregateFunction()
   at Telerik.WinControls.UI.PivotFieldListVisualItem.aggregateOptionsMenuItem_Click(Object sender, EventArgs e)
   at Telerik.WinControls.RadElement.OnClick(EventArgs e)
   at Telerik.WinControls.UI.RadMenuItem.OnClick(EventArgs e)
   at Telerik.WinControls.RadElement.DoClick(EventArgs e)

...

Is it a bug and is there a workaround?

Alex

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 05 Mar 2018, 02:58 PM
Hi Alex,

Thank you for writing.

I managed to reproduce the reported exception. Actually, the available menu items for the calculated fields should be less excluding the More Aggregates Options as well as the other predefined functions above the first separator item. The issue is logged on our feedback portal, here: FIX. RadPivotFieldList - wrong menu items in the context menu of a calculated field leading to an exception. I have updated your Telerik points. It will be fixed with the R2 2018 version of the controls.

As a workaround, you can create a custom visual item and override its UpdateContextMenu method: 
public partial class Form1 : Form
{
    private LocalDataSourceProvider provider;
 
    public Form1()
    {
        InitializeComponent();
 
        //Setup pivot and add calculated field
 
        //Workaround
        this.radPivotFieldList1.ValuesControl.CreatingVisualListItem += ValuesControl_CreatingVisualListItem;
    }
 
    private void ValuesControl_CreatingVisualListItem(object sender, CreatingVisualListItemEventArgs args)
    {
        args.VisualItem = new MyPivotFieldListVisualItem(this.radPivotFieldList1.ViewModel);
    }
}
 
public class MyPivotFieldListVisualItem : PivotFieldListVisualItem
{
    FieldListViewModel viewModel;
 
    public MyPivotFieldListVisualItem(FieldListViewModel viewModel)
        : base(viewModel)
    {
        this.viewModel = viewModel;
    }
 
    protected override void UpdateContextMenu()
    {
        base.UpdateContextMenu();
 
        PivotFieldListItemButton button = (PivotFieldListItemButton)typeof(PivotFieldListVisualItem).GetField("button", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(this);
        string providerName = this.viewModel.DataProvider != null ? this.viewModel.DataProvider.GetType().FullName : String.Empty;
        if (this.Data == null)
        {
            return;
        }
 
        if (this.Data.DataBoundItem is Value && !(providerName.Contains("Xmla") || providerName.Contains("Adomd")))
        {
            for (int i = 0; i < 5; i++)
            {
                button.Items.RemoveAt(i);
            }
        }
    }
}

I hope this helps. Let me know if you have other questions.

Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Alex Dybenko
Top achievements
Rank 2
answered on 06 Mar 2018, 08:41 AM

Thanks Hristo,

that helps. Agree that Sum, Count, Avg items can be removed, but I would be good to have an option to rename calculated field as other fields

Alex

 

 

 

Tags
PivotGrid and PivotFieldList
Asked by
Alex Dybenko
Top achievements
Rank 2
Answers by
Hristo
Telerik team
Alex Dybenko
Top achievements
Rank 2
Share this question
or