FlexReport for .NET | ComponentOne
Reports in WinForms / Sort Data
In This Topic
    Sort Data
    In This Topic

    Sorting is another way to organize data. It can be either ascending or descending. FlexReport allows sorting through DataSource.SortDefinition. Let us suppose you want to display product details with their names in ascending order in the report created in Quick Start. For doing so, follow these steps to sort the product names in alphabetical order.

    1. Add a C1Button to the form and set its Name property to btnSortData and Text property to Sort Product by Name.
    2. Create Click event for the button, named as btnSortData_Click.
    3. Add the following code to the btnSortData_Click event handler to sort the product names in the Product Report in ascending order.
      C#
      Copy Code
      bool asc;
      private void btnSortData_Click(object sender, EventArgs e)
      {
          if (asc)
          {
              SortDefinition sd = new SortDefinition("[Name]", SortDirection.Ascending);
              flexReport.DataSource.SortDefinitions.Add(sd);
              asc = false;
          }
          else
          {
              btnLoad.PerformClick();
              asc = true;
          }
      }
      
    4. Click Sort Product by Name button to view sorting in report as shown in the below image.

      flexreport-sorting-output