Telerik报告?下载30天免费试用

以编程方式访问报表项

在下面的示例中,我们将展示如何从报表内部和从调用应用程序访问报表项。在第一个例子中,让我们从详细信息部分ItemDataBinding eventandler访问一个TextBox项。

从事件中访问报表项

  1. 在设计器中选择详细信息部分,并在Properties窗口的Events选项卡中,找到ItemDataBinding条目并双击。

  2. 事件处理程序传入“sender”,它是表示处理期间的部分的Telerik.Reporting.Processing.DetailSection。因此你可以推导出:

    • 表示正在处理的记录的底层数据的数据对象。

    • 所有处理报表项。

  3. 使用ElementTreeHelper。GetChildByName ()方法定位报表上的项。在下面的代码示例中GetChildByName用于检索“textBox1”文本框。

在下面的代码示例中,我们引用的是处理。文本框,而不是Report1。文本框.的处理。文本框表示处理期间的文本框,其属性集与Report1。文本框在定义报表时使用。

private void detail_ItemDataBinding(对象发送方,EventArgs e) {Telerik.Reporting.Processing.DetailSection section =(发送方为Telerik.Reporting.Processing.DetailSection);Telerik.Reporting.Processing.TextBox txt = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper。GetChildByName(部分,“textBox1”);对象标题= section.DataObject[" title "];if ((string)title == "Developer") {txt.Style.BackgroundColor = System.Drawing.Color.Blue;}}
私有子detail_ItemDataBinding(sender As Object, e As EventArgs) Dim section As Telerik.Reporting.Processing.DetailSection = TryCast(sender, Telerik.Reporting.Processing.DetailSection) Dim txt As Telerik.Reporting.Processing.TextBox = DirectCast(Telerik.Reporting.Processing.ElementTreeHelper。如果DirectCast(title, String) = "Developer"则txt.Style.BackgroundColor = System.Drawing.Color.Blue结束如果结束子

从调用应用程序访问项

如果我们在WinForm或WPF窗口的上下文中,并且需要从报表中访问显示在带有嵌入式报表引擎的ReportViewer控件中的项,则可以直接按照报表层次结构进行操作。我们使用与分配给ReportViewer控件的报表源相同类型的报表源对象。考虑以下代码:

protected void Button1_Click(对象发送器,EventArgs e) {Telerik.Reporting.InstanceReportSource instanceReportSource = (Telerik.Reporting.InstanceReportSource)this.reportViewer1.ReportSource;Telerik.Reporting.Report report = (Telerik.Reporting.Report)instanceReportSource.ReportDocument;Telerik.Reporting.TextBox txt = report.Items。Find("productNameDataTextBox", true)[0] as Telerik.Reporting.TextBox;}
Protected Sub Button1_Click(sender As Object, e As EventArgs) Dim instanceReportSource As telerak . reporting . instanceReportSource = DirectCast(Me.reportViewer1. reportviewsource)作为Telerik.Reporting.Report = DirectCast(instanceReportSource. instanceReportSource)作为Telerik.Reporting.TextBox = TryCast(report.Items. report)。Find("productNameDataTextBox", True)(0), Telerik.Reporting.TextBox)结束子目录

从Table项访问报表字段

您可以使用report API层次结构轻松地从表项引用报表字段。考虑以下代码:

private void tableTextBox_ItemDataBinding(object sender, EventArgs EventArgs){//从发送者对象获取文本框telerick . reporting . processing . textbox textbox = (telerick . reporting . processing . textbox)sender;//获取表对象Telerik.Reporting.Processing.Table table = (Telerik.Reporting.Processing.Table)textBox.Parent;//获取Telerik.Reporting.Processing.DetailSection detail = (Telerik.Reporting.Processing.DetailSection)table.Parent;//直接从报表数据源获取原始值。值= detail.DataObject["Data"];}
私有子tableTextBox_ItemDataBinding(sender作为对象,eventArgs作为eventArgs)Dim textbox As Telerik.Reporting.Processing.TextBox = DirectCast(sender, Telerik.Reporting.Processing.TextBox)“textBox. reports . processing . table = DirectCast(textBox. reports . processing . table = DirectCast)”家长,Telerik.Reporting.Processing.Table)作为Telerik.Reporting.Processing.DetailSection = DirectCast(表。家长,Telerik.Reporting.Processing.DetailSection)直接从报表数据源文本框中获取原始值。Value = detail.DataObject("Data")结束
在本文中
Baidu
map