Print DataTable.frx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Report ScriptLanguage="CSharp" ReportInfo.Description="This example demonstrates how to print a datasource using the TableObject. To do this:&#13;&#10;- select the Table object;&#13;&#10;- go to the &quot;Properties&quot; window and click the &quot;Events&quot; button to view a list of available events;&#13;&#10;- doubleclick the &quot;ManualBuild&quot; event;&#13;&#10;- you will see an empty event handler. You need to print rows using TableObject.PrintRow method; in each row, you must also print all columns (using PrintColumn method). See the script's code for more details." ReportInfo.Created="08/01/2008 14:01:38" ReportInfo.Modified="04/07/2023 14:28:04" 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. private void Table1_ManualBuild(object sender, EventArgs e)
  21. {
  22. // get the &quot;Customers&quot; datasource
  23. DataSourceBase customers = Report.GetDataSource(&quot;Customers&quot;);
  24. // init it
  25. customers.Init();
  26. // number of columns in the datasource
  27. int colCount = customers.Columns.Count;
  28. // print the table header which contains column titles. It's a row with index = 0.
  29. Table1.PrintRow(0);
  30. for (int i = 0; i &lt; colCount; i++)
  31. {
  32. // fill the cell with column title
  33. Cell1.Text = customers.Columns[i].Alias;
  34. // print it
  35. Table1.PrintColumn(0);
  36. }
  37. // now print a datasource content
  38. while (customers.HasMoreRows)
  39. {
  40. // print the table body. It's a row with index = 1.
  41. Table1.PrintRow(1);
  42. for (int i = 0; i &lt; colCount; i++)
  43. {
  44. // fill the cell with datasource column's data
  45. Cell2.Text = customers[customers.Columns[i]].ToString();
  46. // print it
  47. Table1.PrintColumn(0);
  48. }
  49. // move to the next row
  50. customers.Next();
  51. }
  52. }
  53. }
  54. }
  55. </ScriptText>
  56. <Dictionary>
  57. <TableDataSource Name="Customers" ReferenceName="NorthWind.Customers" DataType="System.Int32" Enabled="true">
  58. <Column Name="CustomerID" DataType="System.String"/>
  59. <Column Name="CompanyName" DataType="System.String"/>
  60. <Column Name="ContactName" DataType="System.String"/>
  61. <Column Name="ContactTitle" DataType="System.String"/>
  62. <Column Name="Address" DataType="System.String"/>
  63. <Column Name="City" DataType="System.String"/>
  64. <Column Name="Region" DataType="System.String"/>
  65. <Column Name="PostalCode" DataType="System.String"/>
  66. <Column Name="Country" DataType="System.String"/>
  67. <Column Name="Phone" DataType="System.String"/>
  68. <Column Name="Fax" DataType="System.String"/>
  69. </TableDataSource>
  70. </Dictionary>
  71. <ReportPage Name="Page1" Landscape="true" PaperWidth="297" PaperHeight="210" RawPaperSize="9" Watermark.Font="Arial, 60pt" LastPageSource="15" FirstPageSource="15">
  72. <ReportTitleBand Name="ReportTitle1" Width="1047.06" Height="47.25" CanGrow="true">
  73. <TextObject Name="Text1" Width="1048.95" Height="37.8" Text="CUSTOMERS TABLE" HorzAlign="Center" VertAlign="Center" Font="Segoe UI, 14pt, style=Bold"/>
  74. </ReportTitleBand>
  75. <DataBand Name="Data1" Top="49.25" Width="1047.06" Height="59.23">
  76. <TableObject Name="Table1" Width="94.5" Height="47.25" FixedRows="1" ManualBuildEvent="Table1_ManualBuild">
  77. <TableColumn Name="Column1" Width="94.5" AutoSize="true"/>
  78. <TableRow Name="Row1" Height="28.35">
  79. <TableCell Name="Cell1" Border.Lines="All" Border.Color="White" Fill.Color="110, 145, 190" Text="Title" HorzAlign="Center" VertAlign="Center" Font="Segoe UI, 9pt, style=Bold" TextFill.Color="White"/>
  80. </TableRow>
  81. <TableRow Name="Row2" AutoSize="true">
  82. <TableCell Name="Cell2" Border.Lines="All" Border.Color="WhiteSmoke" Text="Data" VertAlign="Center" Font="Segoe UI, 9pt"/>
  83. </TableRow>
  84. </TableObject>
  85. </DataBand>
  86. <PageFooterBand Name="PageFooter1" Top="110.48" Width="1047.06" Height="28.35" Fill.Color="WhiteSmoke">
  87. <TextObject Name="Text12" 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>