ComponentOne FlexReport for WinForms
Sorting Data
Working with FlexReport > Sorting Data

Sorting is another way to organize data in ascending or descending order.

In FlexReport, sorting is achieved by using DataSource.SortDefinitions.

Lets say you want to view the list of employees with their names in ascending order. In this case the list should be sorted by First Name. The following steps illustrate how to Sort the names of the list of employees in alphabetical order. This example uses sample created in FlexReport Quick Start.

  1. Add a C1Button to the form in the FlexReport Quick Start project.
  2. Set the C1Button Name to 'sortC1Button' and Text to 'Sort Report by Employee First Name'.
  3. Create Click event as sortC1Button_Click.
  4. Add the following code.
    Private asc As Boolean = True
        Private Sub sortC1Button_Click(sender As Object, e As EventArgs) Handles Button2.Click
            If asc Then
                Dim sd As New SortDefinition("[FirstName]", SortDirection.Ascending)
                C1FlexReport1.DataSource.SortDefinitions.Add(sd)
                asc = False
            Else
                btnEmployees.PerformClick()
                asc = True
            End If
            C1FlexReport1.Render()
        End Sub
    
     bool asc = true;
            private void sortC1Button_Click(object sender, EventArgs e)
            {
                if (asc)
                {
                    SortDefinition sd = new SortDefinition("[FirstName]", SortDirection.Ascending);
                    c1FlexReport1.DataSource.SortDefinitions.Add(sd);
                    asc = false;
                }
                else
                {
                    btnEmployees.PerformClick();
                    asc = true;
                }
                c1FlexReport1.Render();
            }
    
  5. Preview the report. Click Employees button to render the report.
  6. Click 'Sort Report by Employee First Name' button to view sorting in the report.

    Sorting Data in FlexReport