用于ActiveReports中文本框控件的简单setter

时间:2013-05-29 14:56:40

标签: c# activereports

如何在ActiveReports 3.1中访问TextBox控件。当我使用ActiveReport 6或更新的下一个代码像魅力一样工作时(我Textbox Name属性"TextBox1")但在3.0版本中它的代码不正确:

this.TextBox1.Text = "Test";

出现编译错误“没有TextBox1的定义”(在6.0中)它工作正常。如何强制此代码正确执行? 这是来自rpx文件的代码

<?xml version="1.0" encoding="utf-16"?>
<ActiveReportsLayout Version="3.1" PrintWidth="9360" DocumentName="ARNet Document" ScriptLang="C#" MasterReport="0">
  <StyleSheet>
    <Style Name="Normal" Value="font-family: Arial; font-style: normal; text-decoration: none; font-weight: normal; font-size: 10pt; color: Black" />
    <Style Name="Heading1" Value="font-size: 16pt; font-weight: bold" />
    <Style Name="Heading2" Value="font-family: Times New Roman; font-size: 14pt; font-weight: bold; font-style: italic" />
    <Style Name="Heading3" Value="font-size: 13pt; font-weight: bold" />
  </StyleSheet>
  <Sections>
    <Section Type="PageHeader" Name="PageHeader1" Height="360" BackColor="16777215" />
    <Section Type="Detail" Name="Detail1" Height="2880" BackColor="16777215">
      <Control Type="AR.Field" Name="TextBox1" Left="1700.787" Top="1247.244" Width="1360.63" Height="340.1574" Text="TextBox1" />
    </Section>
    <Section Type="PageFooter" Name="PageFooter1" Height="360" BackColor="16777215" />
  </Sections>
  <ReportComponentTray />
  <Script><![CDATA[public void Detail1_Format()
{
    this.TextBox1.Text = "test";
}public void ActiveReport_ReportStart()
{

}


]]></Script>
  <PageSettings />
  <Parameters />
</ActiveReportsLayout>

这是错误 enter image description here

2 个答案:

答案 0 :(得分:1)

您能否确保报告中有一个名为“TextBox1”的文本框控件?名称在C#中区分大小写。也许有一个名为'textBox1'的人。

答案 1 :(得分:1)

看起来您在基于XML(.rpx)的报告中使用脚本而不是纯粹基于代码的报告。在较旧版本的ActiveReports中使用基于XML的报告(.rpx文件)时,您必须通过集合访问控件,如下所示:

((DataDynamics.ActiveReports.TextBox)rpt.Sections["Detail1"].Controls["TextBox1"]).Text = "Hello World";

但是,在当前版本的ActiveReports(ActiveReports 7)中,此限制已被删除,因此您可以按如下方式编写代码:

this.TextBox1.Text = "Hello World";