Solved

Manipulating SortFields dynamically in Crystal Reports.Net

Posted on 2004-10-05
3
1,178 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now