C# Telerik报告:在运行时添加文本框不会显示

C# Telerik报告:在运行时添加文本框不会显示,c#,asp.net-mvc-4,dynamic,runtime,telerik-reporting,C#,Asp.net Mvc 4,Dynamic,Runtime,Telerik Reporting,我目前正在使用Telerik Reporting(2013年第1季度发布)编写一份报告,并试图在运行时将文本框添加到标题中(最终也添加到细节部分),但问题是添加的文本框没有显示出来。我不确定它为什么不显示,但添加后没有出现错误。现在我正在尝试在itemdatabinding事件期间添加它。我的代码如下: public partial class _WellPlateReport : Telerik.Reporting.Report { public _WellPlateReport(Dict

我目前正在使用Telerik Reporting(2013年第1季度发布)编写一份报告,并试图在运行时将文本框添加到标题中(最终也添加到细节部分),但问题是添加的文本框没有显示出来。我不确定它为什么不显示,但添加后没有出现错误。现在我正在尝试在itemdatabinding事件期间添加它。我的代码如下:

public partial class _WellPlateReport : Telerik.Reporting.Report
{
  public _WellPlateReport(Dictionary<string, object> ReportParameters)
  {
    //
    // Required for telerik Reporting designer support
    //
    InitializeComponent();
    tbGenotype.Visible = false;
    //
    // TODO: Add any constructor code after InitializeComponent call
    //
  }

  private void labelsGroupHeaderSection_ItemDataBinding(object sender, EventArgs e)
  {
    string temp = "";

    Telerik.Reporting.Processing.GroupSection headerGroup = (Telerik.Reporting.Processing.GroupSection)sender;

    Telerik.Reporting.TextBox tb = new Telerik.Reporting.TextBox();
    tb.Left = new Telerik.Reporting.Drawing.Unit(0.5, UnitType.Inch) + tbGenotype.Left +   tbGenotype.Width;
    //tb.Width = new Telerik.Reporting.Drawing.Unit(3.0, UnitType.Inch);
    tb.Size = tbSex.Size;
    tb.Name = "TestLabel1";
    tb.Value = "Test Label";
    tb.Location = new Telerik.Reporting.Drawing.PointU(tbGenotype.Left + tbGenotype.Width + new Telerik.Reporting.Drawing.Unit(0.5, UnitType.Inch), Telerik.Reporting.Drawing.Unit.Inch(0D));

    //this.labelsGroupHeaderSection.Items.Add(tb);
    //this.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { tb });

    this.labelsGroupHeaderSection.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { tb });
  }
}
public partial class\u WellPlateReport:Telerik.Reporting.Report
{
公共报表(字典报表参数)
{
//
//telerik Reporting designer支持所需
//
初始化组件();
tbgenetic.Visible=false;
//
//TODO:在InitializeComponent调用后添加任何构造函数代码
//
}
私有无效标签GroupHeaderSection_ItemDataBinding(对象发送方,事件参数e)
{
字符串temp=“”;
Telerik.Reporting.Processing.GroupSection headerGroup=(Telerik.Reporting.Processing.GroupSection)发送方;
Telerik.Reporting.textb=新Telerik.Reporting.TextBox();
tb.Left=新的Telerik.Reporting.Drawing.Unit(0.5,UnitType.Inch)+tbgeneric.Left+tbgeneric.Width;
//tb.Width=新电传报告图纸单位(3.0,UnitType.Inch);
tb.Size=tbSex.Size;
tb.Name=“TestLabel1”;
tb.Value=“测试标签”;
tb.Location=新Telerik.Reporting.Drawing.PointU(tbgenetic.Left+tbgenetic.Width+newtelerik.Reporting.Drawing.Unit(0.5,UnitType.Inch),Telerik.Reporting.Drawing.Unit.Inch(0D));
//此.labelGroupHeaderSection.Items.Add(tb);
//this.Items.AddRange(新的Telerik.Reporting.ReportItemBase[]{tb});
this.labelGroupHeaderSection.Items.AddRange(新的Telerik.Reporting.ReportItemBase[]{tb});
}
}
TBGenype是另一个文本框,新的文本框将在运行时添加到旁边,因此我使用它的定位来放置动态文本框。有未知数量的额外列需要添加,但我不确定这为什么不起作用。我的搜索显示其他人也以类似的方式添加控件


更新:还要注意,文本框是在VisualStudio的设计器中添加的。尝试在其上设置visible属性有效,但将文本框添加到标题无效。

请尝试查看。我注意到的唯一区别是,他们正在将文本框添加到面板中。然后,他们将面板添加到报告中。检查是否在面板中添加了TBGenype,但我认为您在报告中添加的每个元素必须首先在同一面板中。

我也有同样的问题,但我注意到当我使用报告查看器中的“刷新”按钮刷新报告时(在我的windows应用程序中;对于web版本,应该是相同的),将显示动态添加的控件。当我第二次刷新时,会显示一组额外的(第二)控件

我的观察结果是:在初始运行时,添加了控件,但不可见(不管visible属性值为true)。在第一次刷新(第二次服务器/应用程序运行)时,将添加第二组控件(不可见),第一组控件现在可见。在第二次刷新/第三次运行时,将添加第三组不可见控件,并显示前两组控件

首先,在再次添加之前,我需要清除父面板中所有动态添加的项。但是,说到问题的关键,调用ReportViewerInstance.RefreshReport()应该会导致动态添加的控件在报表的初始呈现之前变得可见。我将尝试这个场景。我还不确定如何调用报表查看器的实例,但至少,我应该能够将实例的引用作为报表参数或类似参数传递

在以下位置找到RefreshReport()调用:

我将在尝试上述操作后更新我的结果

更新:RefreshReport对我不起作用-它取消了处理并导致没有报告。然而,我确实解决了我的问题。而且,它也应该解决OP的问题

Eric的代码演示了如何在ItemDataBinding事件中创建和显示动态添加的控件。我也这么做了,还尝试了ItemDataBound。这两个事件都发生在处理过程中,一个关于动态添加的表控件的帮助主题提示我。Telerik专家建议在处理过程中不要更改报告项,以避免不可预测的行为。随后,我将创建控件的代码移动到一个方法(不是事件)中,并在实例化所有需要的数据对象之后,以及在将报表数据源设置为对象集合之一之前,从我的Report.NeedDataSource事件调用它。这太棒了


我希望这对其他人有帮助

我从你的链接中查看了文档,基本上我也在做同样的事情。我添加了name属性并更改了大小和位置,我可以看到文本框被添加到items集合中,但该控件在label header部分的报表上的任何位置都不可见。更新:我将telerik reporting DLL更新到2014年第1季度,同样的问题也存在。控件已添加,但不可见且未呈现。请尝试添加文本框,然后将模板保存到文件中。然后用designer打开它,看看文本框是否在那里。Pepo,我不太确定你把模板保存到文件是什么意思。所有这些报告都是在VisualStudio中创建的,而不是使用Telerik的报告编辑器(使用VisualStudio中的编辑器)