Solved

Manipulating SortFields dynamically in Crystal Reports.Net

Posted on 2004-10-05
3
1,201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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. …
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…

739 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