Stimulsoft Reports.Net开发者常见Q&A——其它常见问题(上)

发布时间 : 2016-01-06 12:09:43.000|阅读 1598 次

概述:本片文章主要介绍Stimulsoft Reports.Net开发者遇到的一些常见问题及解决方案。

相关链接:

< Stimulsoft Reports.Net v2015.3最新版本下载>

1.如何修改数据的排序?

代码如下:

DataBand1.Sort = new string[2]
{
"ASC",
"Name"
};

2.如何得到一个组件的实际尺寸大小?

使用StiComponent.GetActualSize方法,该方法返回组件的尺寸。但是,请注意,如果你想要该方法返回CanGrow属性的正确数据,CanShrink和AutoWidth属性必须设置为true。

3.怎么通过组件的名称查找组件?

代码如下:

C#

StiComponent component = report.GetComponentByName("ComponentName");

VB

Dim Component As StiComponent = Report.GetComponentByName("ComponentName");  

4.怎么获取或设置文本为rtf组件的rtf格式?

使用StiRichText.RtfText属性。

5.怎么用代码给组件添加书签?

使用以下代码:

component.Bookmark = "{Categories.CategoryName}";

6.Text和TextValue之间的区别是什么?

Text属性中的文本表达式在报表渲染时被计算、被保存,将计算出一个结果值后会放置在TextValue中。换句话说就是你可以指定表达式。示例如下:

text1.Text = "Phone: {Customers.Phone}";

在TextValue中,你只可以指定字符串:

text1.TextValue = "123";

如果Text和TextValue一块被指定,那么TextValue输出将会被使用。

7.我应该在图像的DataColumn字段指定什么?

在该字段你需要指定数据源和数据列。示例如下:
Customers.Photo

注意不能放括号。你也可以通过链接进行调用。如下:
Products.Customers.Photo

8.怎么从路径加载保存在数据库中的图像?

使用BeforePrintEvent事件,在事件中指定以下代码:

C#

Image1.Image = Image.FromFile(MyDataSource.ImagePath);

VB

Image1.Image = Image.FromFile(MyDataSource.ImagePath)

你还可以使用ImageData属性:

C#

{Image.FromFile(MyDataSource.ImagePath)}

VB

{Image.FromFile(MyDataSource.ImagePath)}

9.如何给Form上的ComboBox绑定数据?

  1. 指定DataBindings属性;
  2. 通过以下代码初始化ComboBox
    ComboBox comboBox = ReportComboBox.Control;
  3. 在FormLoad事件中填充组合框:
    ReportComboBox.Items.Add("123");

10.怎么访问报表的代码文本?

使用StiReport类的Script属性。该属性包含报表的代码文本。

11.怎么将报表生成一份新的代码?

使用StiReport类的ScriptNew方法。代码如下:

C#

StiReport report = new StiReport();
report.ScriptNew();

VB

Dim Report As StiReport = New StiReport()
Report.ScriptNew()

12.怎么更新报表的代码?

使用StiReport类的ScriptUpdate方法来更新报表的代码。方法如下:

C#

StiReport report = new StiReport();
report.ScriptUpdate();

VB

Dim Report As StiReport = New StiReport()
Report.ScriptUpdate()

需注意的是,在报表编译前,报表代码会自动更新。因此没必要调ScriptUpdate方法。

13.如何在报表中使用自定义程序集?

确保属性窗口可见并且选中(按F4键一次或两次或通过菜单“View” -> “Properties”)。在属性窗口中选择组合框中最上面的项目(例如:“MyReport:Report”),将会出现“Referenced Assemblies“属性,点击[…]按钮编辑其值。添加你的程序集,点击[OK]按钮。现在你就可以使用报表代码中自定义程序集中的功能了。

14.怎么从一个报表访问我的应用程序中的对象?

步骤如下:

  1. 你需要添加你应用程序的相关程序集,在报表的ReferencedAssemblies属性中添加。
  2. 然后描述包含报表类中数据的字段。如果你想在没有完整字段路径的情况下描述字段,那么你还需要添加你的类型的命名空间。
  3. 在报表渲染前初始化描述的字段。

C#

StiReport report = new StiReport();
report.Load("report.xml");
//Compile the report first
report.Compile();
//Initialize the field in a report
report.CompiledReport["Parameters"] = OurParameters;
report.Render();

VB

Dim Report As StiReport = New StiReport()
Report.Load("report.xml")
'Compile the report first
Report.Compile()
'Initialize the field in a report
Report.CompiledReport("Parameters") = OurParameters
Report.Render()

在上面的步骤都完成后你就可以从脚本中访问你的应用程序字段了。示例:
{Parameters.SomeParameter}

15.怎么处理名称为C#关键字的列?

在列名称前添加一个@符号,示例:@class

购买最新正版授权!详情请"咨询在线客服"

迎春纳福,金猴献瑞,革新之年双节同庆,惠享不停惊喜连连!优惠详情点击查看>>


在线
客服
微信
QQ 电话
023-68661681
返回
顶部