Groups are created in any report to organize and summarize the data in a particular order. Grouping allows you to visually separate groups of records and hence enhance the readability of the report. How good would it be if you could re-arrange the already created groups without the need for re-designing the whole report? The re-ordering of groups can be implemented in ActiveReports with the help of the DataField property of the Groups.

Implementation

In ActiveReports a group uses a DataField property to organize the data in a data region. Hence, in order to modify or re-order the existing groups, you just need to change its DataField property. On running the attached sample you will observe that the initial grouping hierarchy is as follows : Country | City However, the hierarchy can be easily re-ordered to : City | Country Just click the 'Re-order Groups’ button and you will see the difference. If you look at the following code, you will observe that every-time the button is clicked, the value for 'DataField' property of the groups and groups' controls is swapped. That's it! This does the trick.

'Fetch the value of each group's DataField property  
Dim grpsec As New GroupHeader  
grpsec = CType(rpt.Sections(1), GroupHeader)</span>  
val1 = grpsec.DataField.ToString  

grpsec = New GroupHeader  
grpsec = CType(rpt.Sections(2), GroupHeader)  
val2 = grpsec.DataField.ToString  

'Swap the DataField value  
Dim grpsec1 As New GroupHeader  
Dim grpsec2 As New GroupHeader  
grpsec1 = CType(rpt.Sections(1), GroupHeader)  
grpsec1.DataField = val2  

grpsec1.Controls(0).DataField = val2  

grpsec2 = CType(rpt.Sections(2), GroupHeader)  
grpsec2.DataField = val1  

grpsec2.Controls(0).DataField = val1 

The output will look something like this : Image1 You may download the attached samples for complete implementation. Download VB Sample Download CSharp Sample