Solved

Manipulating SortFields dynamically in Crystal Reports.Net

Posted on 2004-10-05
3
1,185 Views
Last Modified: 2012-08-14
I am migrating my application from ASP to ASP.Net. In ASP the report sort fields could have been added dynamically (<reportobject>.RecordSortFields.Add) using the report document object model. However, I am not able to do the same using the crystalreports.net object model. All I have is ReportDocument.DataDefinition.SortFields collection which does not provide a sort method. Any idea how I can achieve this in .Net?
0
Comment
Question by:skpatra
  • 2
3 Comments
 
LVL 10

Expert Comment

by:ebolek
ID: 12242654
Here you go. This will help you
Regards
Emre

Dim crSortFields As CrystalDecisions.CrystalReports.Engine.SortFields

  Dim crSortField As CrystalDecisions.CrystalReports.Engine.SortField

  Dim crField As CrystalDecisions.CrystalReports.Engine.FieldDefinition

  Dim intCount As Integer

  Dim strTemp As String

  crSortFields = report.DataDefinition.SortFields



  'Find the Summary that I want to set the GroupSort to



  For intCount = 0 To report.DataDefinition.SummaryFields.Count - 1

     strTemp = report.DataDefinition.SummaryFields(intCount).Name

     If strTemp = "Sum ({@Room_Rev}, {GroupView.Group_Comp_Name})" Then

         crField = report.DataDefinition.SummaryFields(intCount)

         Exit For

     End If

  Next



  'Find the Group Sort and change it to the new group sort



  For Each crSortField In crSortFields

      If crSortField.Field.Name = "Group_Comp_Name" Then

          If crSortField.SortType = SortFieldType.GroupSortField Then



               'This is where the error is thrown



               crSortField.Field = crField

               crSortField.SortDirection = SortDirection.DescendingOrder

          End If

      End If

  Next



  report.SetDataSource(ViewReportsDataSet)

  ReportViewer.ReportSource = report

0
 
LVL 3

Author Comment

by:skpatra
ID: 12246257
Thanks a lot for the codeEmre. What I really want to do though is to add a new sort field (instead of updatig the field already existing). Unfortunately crSortFields does not have an Add method. Is there a workaround?
0
 
LVL 10

Accepted Solution

by:
ebolek earned 125 total points
ID: 12248071
This version doesnt let you to fo that. You have to use RDC to add a new sort field. However you can chnage the existing sort field. So hopefully that is enouhg for you. My code shows how to do that

Regards
Emre
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Crystal Reports 11 Ignoring Parameters 3 81
String to Date Formula Failure 2 49
"A string is required here" error in Formula 7 50
Crystal Reports Subreport details 16 58
Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question