在运行时更改Crystal Report文本对象文本

时间:2013-02-01 07:32:20

标签: vb.net object text crystal-reports edit

我在我的项目中使用Crystal Report。它工作得很好,但我只是想让它更灵活。 我有文本对象,其中包含文本。它们不受约束,因为它们只是我报告的附加信息。如何在运行时使这些文本对象可编辑?像鼠标点击一样,用户可以像我在设计中那样编辑它?我需要在项目中添加程序吗?我正在使用vb.net 2010

我使用此代码来调用我的报告

Dim sett As New DataSet1
Dim oRpt As New Accountability
Dim obj As CrystalDecisions.CrystalReports.Engine.TextObject
obj = oRpt.ReportDefinition.Sections("Section5").ReportObjects.Item("txtRel")
'Connection code, sql query here
Rpt.SetDataSource(dta)
frmReport.CrystalReportViewer1.ReportSource = oRpt
frmReport.CrystalReportViewer1.RefreshReport()
frmReport.Show()

我需要编辑的文本对象没有绑定。它是在设计时创建的

2 个答案:

答案 0 :(得分:4)

Private Sub Form1_Load(sender as Object, e as EventArgs) Handles MyBase.Load
    Dim oRpt As New Accountability

    frmReport.CrystalReportViewer1.ReportSource = oRpt
    frmReport.Show()
End Sub

Private Sub btnChangeText_Click(sender as Object, e as EventArgs) Handles btnChangeText.Click
    Dim oRpt As New Accountability
    ' Change the text of the TextObject you want to change here
    DirectCast(oRpt.ReportDefinition.ReportObjects("Text1"), TextObject).Text = "Your Text"
    DirectCast(oRpt.ReportDefinition.ReportObjects("Text2"), TextObject).Text = "Your Second Text"

    frmReport.CrystalReportViewer1.ReportSource = oRpt
    frmReport.CrystalReportViewer1.RefreshReport()
    frmReport.Show()
End Sub

这就是你所需要的!

答案 1 :(得分:-1)

Dim objText As CrystalDecisions.CrystalReports.Engine.TextObject =  
       Report.ReportDefinition.Sections(1).ReportObjects("txtDate")

objText.Text = frmList.txtCall.Text