Calculated Field rename error

3 posts, 1 answers
  1. Alex Dybenko
    Alex Dybenko avatar
    161 posts
    Member since:
    Jan 2005

    Posted 05 Mar 2018 Link to this post

    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. Answer
    Hristo
    Admin
    Hristo avatar
    1522 posts

    Posted 05 Mar 2018 Link to this post

    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.
  3. Alex Dybenko
    Alex Dybenko avatar
    161 posts
    Member since:
    Jan 2005

    Posted 06 Mar 2018 in reply to Hristo Link to this post

    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

     

     

     

Back to Top