Data Dynamics Reports Online Help
Walkthrough: Sorting
See Also Support Forum
User Guide > Samples and Walkthroughs > Walkthroughs > Walkthrough: Sorting

Glossary Item Box

This walkthrough illustrates how to sort data when using a data source that does not allow sorting within the query.

The walkthrough is split up into the following activities:

To complete the walkthrough, you must have access to the Factbook sample database included with this installation.

When you are finished you will have a report that looks similar to the following.

Creating a Data Dynamics Report

To create a report in Visual Studio

  1. Create a new project in Visual Studio.
  2. From the Visual Studio Project menu, select Add New Item.
  3. In the Categories pane, select Data Dynamics Reports.
  4. In the Templates pane, select Report and name the report Elevation.rdlx.
  5. Click Add in Visual Studio 2005.

Connecting the report to a data source

To connect the report to a data source

  1. If the Data Explorer is not in view, from the View menu, select Other Windows, then Data Dynamics Reports Data Explorer (at the bottom).
  2. Click the Add icon and select the Data Source... option.
  3. In the Report DataSource smart panel that appears, select the General page.
  4. Change the Name to Factbook.
  5. Check the Shared Reference checkbox.

  6. Click the Browse button and select Factbook.rdsx, which is located in C:\My Documents\Data Dynamics\Reports\build number\Samples\Factbook. 
    Note: In Windows Vista, the path is C:\User\your name\Documents\Data Dynamics\Reports\build number\Samples\Factbook\.
  7. Click the Accept button in the lower right corner to close the smart panel and see Factbook appear in the Data Explorer.

Adding a dataset

To add a dataset

  1. Click the Add icon and select the Data Set... option.
  2. In the DataSet smart panel that appears, select the General page.
  3. Change the Name to Elevation.
  4. On the Query page, enter the following XML path into the Query text box to access data for every country except "World": 

    //country [@name != 'World']

  5. On the Fields page, enter the values in the table below to create fields for your report. Values for XML data fields must be valid XPath expressions. The three fields marked in bold are the minimum required to make this walkthrough run.
    Tip: XML data always returns strings, so in order to sort by numeric values, you must first convert the data to numeric format. This is accomplished using calculated fields (LowNumber and HighNumber below).
    Field Name Type Value
    CountryName Database Field @name
    LowPoint Database Field ./ElevationExtremesM/LowestPointName
    LowElevation Database Field ./ElevationExtremesM/LowestPointElevation
    HighPoint Database Field ./ElevationExtremesM/HighestPointName
    HighElevation Database Field ./ElevationExtremesM/HighestPointElevation
    LowNumber Calculated =Convert.ToDouble(Fields!LowElevation.Value)
    HighNumber Calculated =Convert.ToDouble(Fields!HighElevation.Value)
    Difference Calculated =Fields!HighNumber.Value - Fields!LowNumber.Value
  6. Click the Accept button in the lower right corner to close the smart panel and see Elevation and the fields appear in the Data Explorer.

Adding controls to contain data

To add controls to the report

  1. From the Toolbox drag a Table data region onto the body of the report and in the Property grid, select values for the following properties as indicated:
    • DataSetName Elevation
    • RepeatHeaderOnNewPage True
  2. Click inside the table to reveal the column and row handles above and to the left of the table.
  3. Right-click any of the column handles above the table and select Insert Column to the Left.
  4. Repeat the previous step until there is a total of seven columns in the table. (You can skip this step if you are only using minimal fields to make the report run.)
  5. Drag the following fields into the detail row of the table and set the Width of each column as indicated below.
    The two fields marked in bold are the minimum required to make this walkthrough run.
    Field Name Column Width
    CountryName TableColumn1 1.25in
    LowPoint TableColumn2 1.7in
    LowNumber TableColumn3 0.7in
    Leave this column blank. TableColumn4 0.2in
    HighPoint TableColumn5 1.7in
    HighNumber TableColumn6 0.7in
    Difference TableColumn7 0.75in
  6. Now that the width of the table is back down to 7in, select the Body of the report and set its Width property to 7in.
  7. Select Report in the combobox above the Property grid, and set the Margins to 0.75in, 0.75in, 0.75in, 0.75in.
    Tip: If the value of the Body Width plus Left Margin plus Right Margin exceeds the paper width, the report shows correctly in Galley mode, but cuts off the right-most column in Print Preview mode and renders it on a separate page.
  8. Click inside the table to reveal the column and row handles, then click the header row handle to select the entire row. In the Property grid, select values for the following properties as indicated:
    • BackgroundColor Gainsboro
    • FontWeight Bold

Previewing the unsorted report

To preview the report

  1. Click the Preview tab of the report designer.
  2. Notice that the data is sorted by country name, as it is in the XML data source.

Sorting the data

To sort the data

  1. Click the Layout tab to return to the report designer.
  2. In the combo box above the Property grid, select the table.
  3. Right-click the edge of the table and select Properties.
  4. In the Table Data Region smart panel that appears, select the Sorting page.
  5. Under Expression, select
    =Fields!HighNumber.Value
  6. Set the Direction to Descending to display the highest points in the world first. (Alternately, you could sort by LowNumber or Difference.)
  7. Click the Accept button in the lower right corner to close the smart panel and accept the sort.
  8. From the File menu, select Save.

Viewing the report

Any report designed with Data Dynamics Reports can be opened in the included Data Dynamics Reports Viewer application or you can view it at design time.

To view the report at design time

  1. Click the Preview tab of the report designer.

To view the report at run time

  1. Add the ReportPreview control to your Visual Studio toolbox and drop it onto your Windows form.
  2. Set the Dock property of ReportPreview1 to Fill so that it will automatically resize if the form is resized at run time.
  3. Double-click the viewer to go to the Load event and use code like the following.
    'Visual Basic.NET 
    Dim rpt As New System.IO.FileInfo(Application.StartupPath & "..\\..\\Elevation.rdlx") 
    Me.ReportPreview1.OpenReport(rpt)
    //C# 
    System.IO.FileInfo rpt = new System.IO.FileInfo(Application.StartupPath + @"..\..\..\Elevation.rdlx"); 
    this.reportPreview1.OpenReport(rpt);
  4. Run the project.

See Also

©2010. GrapeCity, inc. All Rights Reserved.