Create Calculated Item programmatiaclly

2 posts, 0 answers
  1. Tim
    Tim avatar
    57 posts
    Member since:
    Oct 2013

    Posted 17 Jul 2014 Link to this post

    Hi All,

    Following this demo,, I'm go one step further to create the calculated items programmatically in c# (instead of aspx). 

    Here's the part of code under onLoad event that I've tried:

                PivotGridCalculatedItem newCalulation = new PivotGridCalculatedItem();
                newCalulation.GroupName = "Testing: XXYY";

                foreach (PivotGridField GridField in RadPivotGrid1.Fields)
                    if (GridField.FieldType.ToString() == "PivotGridColumnField" && GridField.UniqueName == "CreationYear")
                        (GridFieldas PivotGridColumnField).CalculatedItems.Add(newCal);

    But it's not working an giving me an 'Object reference not set to an instance of an object.' error. Please advise.

    Best regards.

  2. Konstantin Dikov
    Konstantin Dikov avatar
    2386 posts

    Posted 22 Jul 2014 Link to this post

    Hello Tim,

    Thank you for contacting Telerik Support.

    From the provided code snippet only it would be impossible for us to determine what is causing the error that you are receiving. For your convenience I am attaching a page with a very simple example, where I am using the code-snippet that you have provided. As you could noticed, the PivotGridCalculatedItem is correctly added, so please see what exactly differs in your actual project.

    If you continue to experience the same issue and in order for us to be able to assist you any further, please try to prepare a very simple, runnable project, replicating the same error, so we could inspect it locally and hopefully, isolate the root of the problem.

    I am looking forward to your reply.

    Konstantin Dikov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top