Results 1 to 4 of 4

Thread: Change the sorting field within groups on runtime

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    245

    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

  2. #2
    Lively Member KTech's Avatar
    Join Date
    Jun 2008
    Location
    Pittsburgh
    Posts
    117

    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:
    1. myReport.DataDefinition.SortFields.clear

    then specify the new sort order using AddItem or some other method

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    245

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width