Reports for WinForms | ComponentOne
C1.C1Report.4 Assembly / C1.C1Report Namespace / Group Class / Sort Property
Example

In This Topic
    Sort Property
    In This Topic
    Gets or sets how the group is sorted.
    Syntax
    'Declaration
     
    Public Property Sort As SortEnum
    public SortEnum Sort {get; set;}
    Remarks

    The specified sorting is applied to the content of the GroupBy property. For example, if GroupBy contains the expression "FirstName" and Sort is set to "Ascending", then the group will be sorted in ascending order based on the content of the "FirstName" column in the data source.

    Note that the sorting is performed by the data source itself, not by C1Report. Because of this, sorting is always based on column names rather than calculated expressions. If the GroupBy property contains a calculated expression, the component will extract the first column name from the expression and will sort based on that value. For example, if GroupBy is set to "Left(FirstName, 3)", the sorting will be based on the "FirstName" column, not on the first three characters of the first names.

    This can present problems in a few cases, especially if you want to sort based on date parts (year, month, quarter). In these cases, the recommended procedure is to add a calculated column to the data source (by changing the SQL statement used to retrieve the data), then set the GroupBy property to the name of the calculated column.

    Example
    The code below uses a SQL statement to add a "HireQuarter" column to the data source, then sorts a group based on this new column. The report will show employees sorted by the quarter when they were hired.
    string sql = 
        "SELECT *, DATEPART('q', HireDate) AS HireQuarter " +
        "FROM Employees";
    c1r.DataSource.RecordSource = sql;
    c1r.Groups[0].GroupBy = "HireQuarter";
    c1r.Groups[0].Sort = SortEnum.Ascending;
    See Also