cancel
Showing results for 
Search instead for 
Did you mean: 

Adding sortfields in crystal reports 2013

Former Member
0 Kudos

Hi everybody.

There is a way to add a sortfield at runtime without loosing the sortfields created at design time?

I have a report with a gruop by invoice_id. This sorts a report invoice_id. In the detail section I have the articles. But I want to let the user to choose the sort oder: by article code or by article description. Using this code I can change the sortfields, but it seems to remove the first sort field, wich need to be the invoice_id

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

Private f_rd_Reporte As ReportDocument

        Dim l_fd_SortField As FieldDefinition 'miembro de CrystalDecisions.CrystalReports.Engine

        l_fd_SortField = f_rd_Reporte.Database.Tables("invoices").Fields("article_cod")

            f_rd_Reporte.DataDefinition.SortFields(0).Field = l_fd_SortField

            f_rd_Reporte.DataDefinition.SortFields(0).SortDirection = SortDirection.AscendingOrder

Using index of 1 instead of 0 gives me an error of "out of index" (DISP_E_BADINDEX).

Need something like an Add method:

f_rd_Reporte.DataDefinition.SortFields.Add(l_fd_SortField, SortDirection.AscendingOrder)




Regards.

Damian.

Accepted Solutions (1)

Accepted Solutions (1)

DellSC
Active Contributor
0 Kudos

Instead of doing this in your application, try using a parameter in the report.  Here's what you can do:

1.  Create a parameter, which I will call {?SortOrder} which has the values "Code" and "Description".

2.  Create a formula that will provide the values for the sort.  It might look like this (assuming that both fields are string fields!):

{@SortOrder}

If {?SortOrder} = 'Code' then {invoices.article_cod} else {invoices.article_descrip}

3.  Sort the report on this formula.

Your application would then just have to supply the value for this parameter base on what the user selects in the application.

-Dell

Former Member
0 Kudos

Nice... thank you.

But if i need more than one sortfield, I need to repeat this parameter field for each... am I righ?

Damian.

DellSC
Active Contributor
0 Kudos

If you have multiple levels of sort, yes, you will have to repeat the process for each level of sort.

What are the specifics of what you're trying to sort on?  I may be able to come up with some shortcuts for you.

-Dell

Former Member
0 Kudos

Hi Dell.

In my specific situation, your suggestion does the job. My question was to see if I understood the solution.

Thank you

Another thing. I added a question on this discussion:

Do you know how can I solve this? I need to create a new discussion?

regards.

Damian.

Answers (1)

Answers (1)

0 Kudos

No hablo ingles pero este problema lo resolvi con solo crear un indice en el reporte, en mi caso, yo debia permitir al usuario generar el crystalreport con tres forma de ordenamiento:

1. por recnum (orden de captura)

2. por descripcion del producto

3. por ubicacion del producto en bodega

el problema radica en que hay que ponerle por defecto, unos de esos tes campos al ordenar el reporte, al momento de diseñar el mismo. Esto deberia resolver tu problema.