Sorting Crystal Reports programmatically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Afonin

    Sorting Crystal Reports programmatically

    Hello,

    I'm still learning Crystal reports, and now I need to sort report
    programmaticall y. I've found a good article about it:
    http://blogs.ittoolbox.com/c/coding/...atically-16201.
    This is how it described there:

    ReportDocument objReport = new ReportDocument( );
    objReport.Load( "Your report path");
    FieldDefinition FieldDef;
    FieldDef = objReport .Database.Table s[0].Fields[sortField];
    objReport.DataD efinition.SortF ields[0].Field = FieldDef;
    objReport.DataD efinition.SortF ields[0].SortDirection =
    CrystalDecision s.Shared.SortDi rection.Descend ingOrder;

    When I try to do this, I'm getting an error on this line:

    objReport.DataD efinition.SortF ields[0].Field = FieldDef;

    Exception from HRESULT: 0x8002000B (DISP_E_BADINDE X))

    This error is also described in this article:

    "This is because you didn't define any sort field in your crytal report...
    so if you try to add a FieldDef to the SortFields at a specified index and
    that index doesn't exist then you will get the error..."

    But there is no explanation how to define the sort fields in the report.
    I've searched the Google and found several posts about the same issue, but
    also no explanation.

    So how can I define the sort fields for the report so I could sort
    programmaticall y?

    I would appreciate your help.

    Thank you,

    Peter


Working...