1647400 - How to Get the sort direction for a group sort using the CR RAS SDK for VS .NET

SAP Knowledge Base Article - Public

1647400 - How to Get the sort direction for a group sort using the CR RAS SDK for VS .NET

Symptom

  • Using Crystal Reports InProc RAS SDK for VS .NET

Environment

  • Crystal Reports for Visual Studio 2010
  • VS2010

Resolution

  • The following C# code gets the group sort direction:
using System.Reflection;
using System.Runtime.InteropServices;
using CrystalDecisions.ReportAppServer.DataDefModel;
 
CrystalDecisions.CrystalReports.Engine.SortFields crystalSortFields = report.DataDefinition.SortFields;
if (crystalSortFields != null)
{
    foreach (CrystalDecisions.CrystalReports.Engine.SortField crystalSortField in crystalSortFields)
    {
        if (crystalSortField.SortType == CrystalDecisions.Shared.SortFieldType.GroupSortField)
        {
            MethodInfo getRasSort = crystalSortField.GetType().GetMethod("get_RasSort", BindingFlags.NonPublic | BindingFlags.Instance);
            object rasSort = getRasSort.Invoke(crystalSortField, System.Type.EmptyTypes);
            IntPtr iunkwn = Marshal.GetIUnknownForObject(rasSort);
            switch ((CrSortDirectionEnum)((dynamic)rasSort).Direction)
            {
                case CrSortDirectionEnum.crSortDirectionAscendingOrder:
                    ...
                    break;
                case CrSortDirectionEnum.crSortDirectionDescendingOrder:
                    ...
                    break;
                case CrSortDirectionEnum.crSortDirectionBottomNOrder:
                case CrSortDirectionEnum.crSortDirectionBottomNPercentage:
                case CrSortDirectionEnum.crSortDirectionNoSortOrder:
                case CrSortDirectionEnum.crSortDirectionTopNOrder:
                case CrSortDirectionEnum.crSortDirectionTopNPercentage:
                default:
                    break;
            }
        }
    }
}

Keywords

CR2010 2010 CR4VS2010 CR4VS VS2010 NET2010 Crystal Reports for .NET Framework 4.0 crforvs 13 up down sorting enum in process report application server , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports, developer version for Microsoft Visual Studio