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, http://www.telerik.com/help/aspnet-ajax/pivotgrid-custom-data-calculations.html, 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
    Admin
    Konstantin Dikov avatar
    1793 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.


    Regards,
    Konstantin Dikov
    Telerik
     

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top