Drill-Down Groups.frx 6.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Report ScriptLanguage="CSharp" ReportInfo.Description="Demonstrates how to create a drill-down group report. The report uses a script to hide or show a group:&#13;&#10;- add CheckBox object on a group header and set up its Hyperlink: set Kind to &quot;Custom&quot; and Value to group's name;&#13;&#10;- create a Click event handler that will be executed when you click the checkbox;&#13;&#10;- create a BeforePrint event handler of a group header. In the handler, check whether current group is visible or not.&#13;&#10;&#13;&#10;See the script's code for more details.&#13;&#10;&#13;&#10;Learn how to build this report on the Fast Reports Academy channel http://fast.report/bab94" ReportInfo.Created="01/17/2008 04:31:41" ReportInfo.Modified="04/07/2023 11:27:17" ReportInfo.CreatorVersion="1.0.0.0">
  3. <ScriptText>using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Windows.Forms;
  8. using System.Drawing;
  9. using System.Data;
  10. using FastReport;
  11. using FastReport.Data;
  12. using FastReport.Dialog;
  13. using FastReport.Barcode;
  14. using FastReport.Table;
  15. using FastReport.Utils;
  16. namespace FastReport
  17. {
  18. public class ReportScript
  19. {
  20. // list of visible groups
  21. private List&lt;string&gt; expandedGroups = new List&lt;string&gt;();
  22. private void GroupHeader1_BeforePrint(object sender, EventArgs e)
  23. {
  24. // check if current group is visible
  25. string groupName = ((String)Report.GetColumnValue(&quot;Products.ProductName&quot;)).Substring(0, 1);
  26. bool groupVisible = expandedGroups.Contains(groupName);
  27. // toggle objects visibility
  28. Data1.Visible = groupVisible;
  29. GroupFooter1.Visible = groupVisible;
  30. // toggle indicator
  31. CheckBox1.Checked = !groupVisible;
  32. }
  33. private void CheckBox1_Click(object sender, EventArgs e)
  34. {
  35. // get a group name
  36. string groupName = (sender as CheckBoxObject).Hyperlink.Value;
  37. // toggle group
  38. if (expandedGroups.Contains(groupName))
  39. expandedGroups.Remove(groupName);
  40. else
  41. expandedGroups.Add(groupName);
  42. // refresh the report
  43. Report.Refresh();
  44. }
  45. }
  46. }
  47. </ScriptText>
  48. <Styles>
  49. <Style Name="EvenRows" Fill.Color="WhiteSmoke" Font="Arial, 10pt" ApplyBorder="false" ApplyTextFill="false" ApplyFont="false"/>
  50. </Styles>
  51. <Dictionary>
  52. <TableDataSource Name="Products" ReferenceName="NorthWind.Products" DataType="System.Int32" Enabled="true">
  53. <Column Name="ProductID" DataType="System.Int32"/>
  54. <Column Name="ProductName" DataType="System.String"/>
  55. <Column Name="SupplierID" DataType="System.Int32"/>
  56. <Column Name="CategoryID" DataType="System.Int32"/>
  57. <Column Name="QuantityPerUnit" DataType="System.String"/>
  58. <Column Name="UnitPrice" DataType="System.Decimal"/>
  59. <Column Name="UnitsInStock" DataType="System.Int16"/>
  60. <Column Name="UnitsOnOrder" DataType="System.Int16"/>
  61. <Column Name="ReorderLevel" DataType="System.Int16"/>
  62. <Column Name="Discontinued" DataType="System.Boolean" BindableControl="CheckBox"/>
  63. <Column Name="EAN13" DataType="System.String"/>
  64. </TableDataSource>
  65. <Total Name="TotalProducts" TotalType="Count" Evaluator="Data1" PrintOn="GroupFooter1"/>
  66. </Dictionary>
  67. <ReportPage Name="Page1" Watermark.Font="Arial, 60pt">
  68. <ReportTitleBand Name="ReportTitle1" Width="718.2" Height="47.25" CanGrow="true">
  69. <TextObject Name="Text1" Width="718.2" Height="37.8" Text="ALPHABETICAL PRODUCT LIST" HorzAlign="Center" VertAlign="Center" Font="Segoe UI, 14pt, style=Bold"/>
  70. </ReportTitleBand>
  71. <GroupHeaderBand Name="GroupHeader1" Top="49.25" Width="718.2" Height="37.8" BeforePrintEvent="GroupHeader1_BeforePrint" KeepWithData="true" Condition="[Products.ProductName].Substring(0,1)" SortOrder="None">
  72. <TextObject Name="Text7" Left="37.8" Top="9.45" Width="359.1" Height="28.35" Border.Color="LightSkyBlue" Fill.Color="110, 145, 190" Hyperlink.Kind="Custom" Hyperlink.Expression="[Products.ProductName].Substring(0,1)" Text="[[Products.ProductName].Substring(0,1)]" Padding="5, 0, 0, 0" VertAlign="Center" Font="Segoe UI, 14pt, style=Bold" TextFill.Color="White"/>
  73. <CheckBoxObject Name="CheckBox1" Left="9.45" Top="14.45" Width="18.9" Height="18.9" Border.Lines="All" Border.Color="DarkGray" Cursor="Hand" Hyperlink.Kind="Custom" Hyperlink.Expression="[Products.ProductName].Substring(0,1)" ClickEvent="CheckBox1_Click" CheckedSymbol="Plus" UncheckedSymbol="Minus"/>
  74. <DataBand Name="Data1" Top="89.05" Width="718.2" Height="18.9" Visible="false" DataSource="Products">
  75. <TextObject Name="Text2" Left="37.8" Width="264.6" Height="18.9" Border.Lines="Left" Border.Color="Gainsboro" EvenStyle="EvenRows" Text="[Products.ProductName]" VertAlign="Center" Font="Segoe UI, 9pt"/>
  76. <TextObject Name="Text4" Left="302.4" Width="94.5" Height="18.9" Border.Lines="Right" Border.Color="Gainsboro" EvenStyle="EvenRows" Text="[Products.UnitPrice]" Format="Currency" Format.UseLocale="true" Format.DecimalDigits="2" HorzAlign="Right" VertAlign="Center" Font="Segoe UI, 9pt"/>
  77. <Sort>
  78. <Sort Expression="[Products.ProductName]"/>
  79. </Sort>
  80. </DataBand>
  81. <GroupFooterBand Name="GroupFooter1" Top="109.95" Width="718.2" Height="18.9" Visible="false" KeepWithData="true">
  82. <TextObject Name="Text8" Left="37.8" Width="359.1" Height="18.9" Border.Lines="Left, Right, Bottom" Border.Color="Gainsboro" Text="Total products: [TotalProducts]" HorzAlign="Right" VertAlign="Center" Font="Segoe UI, 9pt, style=Bold"/>
  83. </GroupFooterBand>
  84. </GroupHeaderBand>
  85. <PageFooterBand Name="PageFooter1" Top="130.85" Width="718.2" Height="28.35" Fill.Color="WhiteSmoke">
  86. <TextObject Name="Text9" Left="623.7" Width="94.5" Height="28.35" Text="[PageN]" HorzAlign="Right" VertAlign="Center" Font="Segoe UI, 9pt"/>
  87. <TextObject Name="Text12" Left="9.45" Width="217.35" Height="28.35" Cursor="Hand" Hyperlink.Value="https://www.fast-report.com/en/product/fast-report-net/" Text="Generated by FastReport" VertAlign="Center" Font="Segoe UI, 9pt, style=Underline" TextFill.Color="Blue"/>
  88. </PageFooterBand>
  89. </ReportPage>
  90. </Report>