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

Create Calculated Item programmatiaclly

1 Answer 8 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 17 Jul 2014, 01:00 PM
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.


1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 22 Jul 2014, 08:06 AM
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.

 
Tags
PivotGrid
Asked by
Tim
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or