Solved

Manipulating SortFields dynamically in Crystal Reports.Net

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

763 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