FAQ/GetCustomHeader.md
... ...
@@ -0,0 +1,64 @@
1
+#GetCustomHeader
2
+
3
+[[_TOC_]]
4
+
5
+##About
6
+
7
+This method can be used to programatically set a unique header on a ReportSet.
8
+
9
+##C# Exmple
10
+
11
+```csharp
12
+public override void GetCustomHeader(ReportSet reportSet, ReportSetResults results, bool print, out string customHeader)
13
+{
14
+ customHeader = "My custom header uses the fields in the report!";
15
+ foreach (Field f in reportSet.Detail.Fields.AsEnumerable().DistinctBy(fld => fld.DbColumn.FullName))
16
+ customHeader += string.Format("</br>[{0}]", f.DbColumn.Name);
17
+ customHeader += "</br>The field names will get replaced with the data in the first row of the detail grid results. But I only appear if there's an existing header on the report.";
18
+}
19
+
20
+public static class LinqExtensions
21
+{
22
+ public static IEnumerable<TSource> DistinctBy<TSource, TKey>
23
+ (this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
24
+ {
25
+ HashSet<TKey> seenKeys = new HashSet<TKey>();
26
+ foreach (TSource element in source)
27
+ {
28
+ if (seenKeys.Add(keySelector(element)))
29
+ {
30
+ yield return element;
31
+ }
32
+ }
33
+ }
34
+}
35
+
36
+```
37
+
38
+##VB.NET Example
39
+
40
+```visualbasic
41
+Public Overrides Sub GetCustomHeader(reportSet As ReportSet, results As ReportSetResults, print As Boolean, ByRef customHeader As String)
42
+ customHeader += "My custom header uses the fields in the report!"
43
+ For Each f As Field In reportSet.Detail.Fields.DistinctBy(Function(fld As Field) fld.DbColumn.FullName)
44
+ customHeader += String.Format("</br>[{0}]", f.DbColumn.Name)
45
+ Next
46
+ customHeader += "</br>The field names will get replaced with the data in the first row of the detail grid results. But I only appear if there's an existing header on the report."
47
+End Sub
48
+
49
+Public Module LinqExtensions
50
+ <Extension()>
51
+ Public Function DistinctBy(Of TSource, TKey) _
52
+ (ByVal source As IEnumerable(Of TSource), ByVal keySelector As Func(Of TSource, TKey)) _
53
+ As IEnumerable(Of TSource)
54
+ Dim seenKeys As New HashSet(Of TKey)()
55
+ Dim toReturn As New List(Of TSource)
56
+ For Each element As TSource In source
57
+ If seenKeys.Add(keySelector(element)) Then
58
+ toReturn.Add(element)
59
+ End If
60
+ Next
61
+ Return toReturn.AsEnumerable()
62
+ End Function
63
+End Module
64
+```
... ...
\ No newline at end of file