Change the sorting field within groups on runtime
Hi. I'm using VS.net 2008 and CR 2008, and I've been trying to change the sorting field within a group during runtime. Here is the code I'm trying:
Code:
Dim myReport As New ReportDocument
Dim fielddef As FieldDefinition
fielddef = myReport.Database.Tables.Item(0).Fields.Item("startnummer")
myReport.DataDefinition.SortFields.Item(0).Field = fielddef
But it only changes the grouping, and I don't want to change that. Is it impossible to change the sorting field without affecting the grouping?
Hope you understand my problem, and thanks for all the help :)
Re: Change the sorting field within groups on runtime
I think you have to clear the existing sort order first. It is something like
vb Code:
myReport.DataDefinition.SortFields.clear
then specify the new sort order using AddItem or some other method
Re: Change the sorting field within groups on runtime
A Group is a SortField.
Loop through all the SortFields checking the SortFieldType for a RecordSortField. If you don't find one, add a new SortField. If you do modify it's FieldDefinition.
Re: Change the sorting field within groups on runtime
Thanks a lot Bruce! I made it work with this code:
Code:
fielddef = myReport.Database.Tables.Item(0).Fields.Item("startnummer")
For Each SortField In myReport.DataDefinition.SortFields
If SortField.SortType = SortFieldType.RecordSortField Then
SortField.Field = fielddef
End If
Next
But this code works only if it finds a RecordSortField. How do I add a new SortField if it can't find a RecordSortField?