Try this: Add a new report to your project and drag and drop a field into it. Run your application and display the report. If you were expecting to see all rows you are in for a surprise: The report only displays the first row!
So what happened? A single textbox can only display one value. So when you drag and drop a field into the report, Report Designer automatically wraps the field in the First() function. The First() function returns the first value in a collection. Deleting the First() function wrapper won't help—it is implied in this situation, even if omitted.
To see all rows you need multiple instances of the textbox, one for each row in the datasource. This is where List comes into the picture. Start over and drag and drop a List to the report. Then drag and drop a field into the List. Notice that this time Report Designer does not wrap the field in a First() function. When you run the report all rows in the datasource are displayed.
By default, no group expression is defined on List. When no group expression is defined, List repeats for each row in the datasource.
When a group expression is defined on a List, the List repeats for each group in the datasource.
Author | Title | Publisher |
---|---|---|
Kernighan | The C Programming Language | Prentice Hall |
Kernighan | The Practice of Programming | Addison-Wesley |
Gray | Transaction Processing | Morgan Kaufmann |
Wirth | Algorithms and Data Structures | Prentice Hall |
Wirth | Compiler Construction | Addison-Wesley |
Let us say you are using a List to display the contents of the Books table shown on the right. If you set the group expression of the List to =Fields!Author.Value then the List will repeat three times since there are three unique authors in this table.
Notice that after setting the group expression as described above, if you drag and drop the Author field into the List, Report Designer does not wrap the field in the First() function, but if you drag and drop the Title or Publisher fields then Report Designer automatically wraps it in the First() function. This is because Report Designer knows that given the above grouping, the Author field has only one value within each group, but Title and Publisher fields may have multiple values. Ony one value can be displayed using a textbox, so the Title and Publisher fields are automatically wrapped in the First() function.
To display all Titles and Publishers within each group you can nest another List or a Table within the first List. For details see Designing master-detail reports.
To define a group expression right-click on the List, then choose Properties. Click the Edit details group button. In the Grouping and Sorting Properties dialog click in Group on Expression, then pick a field from the dropdown.
To start a new page for each instance of the group, check the Page break at end checkbox in Grouping and Sorting Properties dialog.
When you nest report items in other report items the containment relationship can be hard to understand just looking at the layout editor. The Document Outline window of Visual Studio can make it easier to see which report item is nested inside which. To open the Document Outline window, from the menu choose View > Other Windows > Document Outline.