Skip to Content

Invalid groupSortDirection returned, after setting enum to "NoSortDirection"

Mar 01 at 10:54 AM


avatar image
Former Member

Hi, we are in process of creating an application to overwrite the grouping and sorting in a report. The application will remove all sort and group fields (using ReportAppServer.Controllers.SortController.Remove) then add back in all sorts. We want to set the sorting to "NoSortDirection". However, if we set it CrSortDirectionEnum.crSortDirectionNoSortOrder it failes with "no valid SortDirection".

  protected void SetSorts (Sorts Sorts, SortController controller )
  foreach ( Sort sort in Sorts )
  sort.Direction = CrSortDirectionEnum.crSortDirectionNoSortOrder;
  controller.Add( -1, sort );

Do i use the modifySortDirection function, instead of removing and adding the Sorts, I get an exception saying "I'm not allowed to change the SortField information"

Why can I set all other enum-values, but not the NoSortOrder?
Where is my error?

I would appreciate any help.


In use:
- SAP Crystal Reports for Visual Studio 2017
- Crystal Reports Version:
- I'm using the in proc RAS API

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Don Williams
Mar 01 at 03:07 PM

Hi Jessica,

That is by design, if you don't want no sort then don't set it.

I noticed the same when I was testing:

Field f = (Field)rptClientDoc.DataDefController.DataDefinition.ResultFields.FindField("TestDon", CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleEnglish);
if (rptClientDoc.DataDefController.SortController.CanSortOn(f))
    Sort mySort = new Sort();
    mySort.Direction = CrSortDirectionEnum.crSortDirectionAscendingOrder;
    mySort.SortField = f;
    rptClientDoc.DataDefController.SortController.Add(-1, mySort);

    //test = (ISCRSort)boFieldObject;
    //test.Direction = CrSortDirectionEnum.crSortDirectionDescendingOrder;

    //    if (Formula.Name == "TestDon")
    //    {
    //        MysortController.add(CrSortDirectionEnum.crSortDirectionNoSortOrder, test);
    //        // if no sort then delete the sort and SAVE the report
    //        //rptClientDoc.SaveAs("don2.rpt", @"D:\Atest\swati\CrystalTest_3501213_2013", 0);
    //    }
    //catch (Exception ex)
    //    btnSQLStatement.Text = "ERROR: " + ex.Message;
{ }

Because there was a work around I never ask R&D to look into it...


10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Mar 07 at 04:17 PM

Hi Don,

we sort our Data in our database, we dont need another sortorder.
That's the reason why I wanted to set it to "noSortDirection".

You said there is a workaround? How does it work?


10 |10000 characters needed characters left characters exceeded