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:
- Creating a Data Dynamics Report
- Connecting the report to an XML data source
- Adding a Dataset
- Adding controls to the report to contain data
- Previewing the unsorted report
- Sorting the data
- Viewing the report
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
- Create a new project in Visual Studio.
- From the Visual Studio Project menu, select Add New Item.
- In the Categories pane, select Data Dynamics Reports.
- In the Templates pane, select Report and name the report Elevation.rdlx.
- Click Add in Visual Studio 2005.
Connecting the report to a data source
To connect the report to a data source
- If the Data Explorer is not in view, from the View menu, select Other Windows, then Data Dynamics Reports Data Explorer (at the bottom).
- Click the Add icon and select the Data Source... option.
- In the Report DataSource smart panel that appears, select the General page.
- Change the Name to Factbook.
- Check the Shared Reference checkbox.

- 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\. - 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
- Click the Add icon and select the Data Set... option.
- In the DataSet smart panel that appears, select the General page.
- Change the Name to Elevation.
- 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']
- 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 - 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
- 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
- Click inside the table to reveal the column and row handles above and to the left of the table.
- Right-click any of the column handles above the table and select Insert Column to the Left.
- 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.)
- 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 - 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.
- 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. - 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
- Click the Preview tab of the report designer.
- Notice that the data is sorted by country name, as it is in the XML data source.
Sorting the data
To sort the data
- Click the Layout tab to return to the report designer.
- In the combo box above the Property grid, select the table.
- Right-click the edge of the table and select Properties.
- In the Table Data Region smart panel that appears, select the Sorting page.
- Under Expression, select
=Fields!HighNumber.Value
- Set the Direction to Descending to display the highest points in the world first. (Alternately, you could sort by LowNumber or Difference.)
- Click the Accept button in the lower right corner to close the smart panel and accept the sort.
- 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
- Click the Preview tab of the report designer.
To view the report at run time
- Add the ReportPreview control to your Visual Studio toolbox and drop it onto your Windows form.
- Set the Dock property of ReportPreview1 to Fill so that it will automatically resize if the form is resized at run time.
- 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);
- Run the project.