on 07-09-2013 10:23 PM
I'm trying to set the Top N options for a group using the CR .NET API. The group already has a Top N sort defined for it in the report file.
My C# code looks like this:
public void SetTopNOptions(bool top, int nGroups, bool discardOthers)
{
ISCRSort groupSort = reportDocument.ReportClientDocument.DataDefController.DataDefinition.Sorts[groupIndex];
TopNSort topNSort = new TopNSort();
topNSort.Direction = top ? CrSortDirectionEnum.crSortDirectionTopNOrder : CrSortDirectionEnum.crSortDirectionBottomNOrder;
topNSort.DiscardOthers = discardOthers;
topNSort.NIndividualGroups = nGroups;
topNSort.SortField = groupSort.SortField;
reportDocument.ReportClientDocument.DataDefController.SortController.Modify(groupSort, topNSort);
}
This succeeds the first time, and I can show the report in a preview control & it displays the correct number of groups.
However, the second time I call this on the same ReportDocument I get a NullReferenceException when I call Modify. I think this is due to the fact that groupSort.SortField is null (and therefore so is topNSort.SortField).
Interestingly, if I try to do this using the Engine classes, I get the same behaviour!
SortField sortField = reportDocument.DataDefinition.SortFields[groupIndex];
TopBottomNSortField tbnsf = sortField as TopBottomNSortField;
if (tbnsf != null)
tbnsf.NumberOfTopOrBottomNGroups = nGroups;
The first time through this code succeeds, but the second time throws a NullReferenceError. I wouldn't be surprised if the Engine-level code is doing something pretty similar to the RAS code above.
Anyway, please repro and file a bug report.
Thanks
- rick cameron
Softrak
Hi Rick,
Try using the .Clone method to make the change from the original sort. That should copy all of the objects and allow you to make the change and then .Modify should work the second time.
Too busy right now to test it...
Log a case in SMP if the above does not work, it has a lot more weight when getting things fixed with a real company attached to it.
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.