使用C1PrintDocument控件 > 数据绑定 > Render对象上的数据绑定 > 数据绑定表 |
通过使用TableVectorGroup的DataBinding属性,可以将一个RenderTable对象进行数据绑定。TableVectorGroup是表格行和列分组的基类。
关于数据绑定到RenderTable的示例,请参见安装在ComponentOne Samples文件夹中的DataBinding示例。
请注意,不仅行分组可以进行数据绑定,列分组也可以。也就是说,一个表格不仅仅可以向下增长,同时也可以横向增长。
分组将生效,但是请注意分组的层次关系基于TableVectorGroup对象的层次关系,如以下代码所示:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Dim rt As C1.C1Preview.RenderTable = New C1.C1Preview.RenderTable rt.Style.GridLines.All = C1.C1Preview.LineDef.Default ' 表头: Dim c As C1.C1Preview.TableCell = rt.Cells(0, 0) c.SpanCols = 3 c.Text = "Header" ' 分组页眉: c = rt.Cells(1, 0) c.Text = "GroupId = [Fields!GroupId.Value]" c.SpanCols = 3 c.Style.TextAlignHorz = C1.C1Preview.AlignHorzEnum.Center c.Style.TextAlignVert = C1.C1Preview.AlignVertEnum.Center ' 子分组页眉: c = rt.Cells(2, 0) c.Text = "GroupId = [Fields!GroupId.Value] SubGroupId = [Fields!SubGroupId.Value]" c.SpanCols = 3 c.Style.TextAlignHorz = C1.C1Preview.AlignHorzEnum.Center c.Style.TextAlignVert = C1.C1Preview.AlignVertEnum.Center ' 子分组数据: rt.Cells(3, 0).Text = "GroupId=[Fields!GroupId.Value]" rt.Cells(3, 1).Text = "SubGroupId=[Fields!SubGroupId.Value]" rt.Cells(3, 2).Text = "IntValue=[Fields!IntValue.Value]" ' 创建一组数据绑定行,按照GroupId字段进行分组: Dim g As C1.C1Preview.TableVectorGroup = rt.RowGroups(1, 3) g.CanSplit = True g.DataBinding.DataSource = MyData.Generate(20, 0) g.DataBinding.Grouping.Expressions.Add("Fields!GroupId.Value") g.Style.BackColor = Color.LightCyan ' 创建一个嵌套分组,按照SubGroupId字段进行分组: Dim ng As C1.C1Preview.TableVectorGroup = rt.RowGroups(2, 2) ng.CanSplit = True ng.DataBinding.DataSource = g.DataBinding.DataSource ng.DataBinding.Grouping.Expressions.Add("Fields!SubGroupId.Value") ng.Style.BackColor = Color.LightPink ' 创建更深一层的嵌套数据绑定分组: Dim ng2 As C1.C1Preview.TableVectorGroup = rt.RowGroups(3, 1) ng2.DataBinding.DataSource = g.DataBinding.DataSource ng2.Style.BackColor = Color.LightSteelBlue |
C#
C# |
拷贝代码
|
---|---|
RenderTable rt = new RenderTable(); rt.Style.GridLines.All = LineDef.Default; // 表头: TableCell c = rt.Cells[0, 0]; c.SpanCols = 3; c.Text = "Header"; // 分组页眉: c = rt.Cells[1, 0]; c.Text = "GroupId = [Fields!GroupId.Value]"; c.SpanCols = 3; c.Style.TextAlignHorz = AlignHorzEnum.Center; c.Style.TextAlignVert = AlignVertEnum.Center; // 子分组页眉: c = rt.Cells[2, 0]; c.Text = "GroupId = [Fields!GroupId.Value] SubGroupId = [Fields!SubGroupId.Value]"; c.SpanCols = 3; c.Style.TextAlignHorz = AlignHorzEnum.Center; c.Style.TextAlignVert = AlignVertEnum.Center; // 子分组数据: rt.Cells[3, 0].Text = "GroupId=[Fields!GroupId.Value]"; rt.Cells[3, 1].Text = "SubGroupId=[Fields!SubGroupId.Value]"; rt.Cells[3, 2].Text = "IntValue=[Fields!IntValue.Value]"; // 创建一组数据绑定行,按照GroupId字段进行分组: TableVectorGroup g = rt.RowGroups[1, 3]; g.CanSplit = true; g.DataBinding.DataSource = MyData.Generate(20, 0); g.DataBinding.Grouping.Expressions.Add("Fields!GroupId.Value"); g.Style.BackColor = Color.LightCyan; // 创建一个嵌套分组,按照SubGroupId字段进行分组: TableVectorGroup ng = rt.RowGroups[2, 2]; ng.CanSplit = true; ng.DataBinding.DataSource = g.DataBinding.DataSource; ng.DataBinding.Grouping.Expressions.Add("Fields!SubGroupId.Value"); ng.Style.BackColor = Color.LightPink; // 创建更深一层的嵌套数据绑定分组: TableVectorGroup ng2 = rt.RowGroups[3, 1]; ng2.DataBinding.DataSource = g.DataBinding.DataSource; ng2.Style.BackColor = Color.LightSteelBlue; |
以上代码可以由以下表格演示:
Header | |||||
Group 1, 3 | GroupId = [Fields!GroupId.Value] | ||||
Group 2, 2 | GroupId = [Fields!GroupId.Value] SubGroupId = [Fields!SubGroupId.Value] | ||||
Group 3, 1 | GroupId=[Fields!GroupId.Value] | SubGroupId=[Fields!SubGroupId.Value] | IntValue=[Fields!IntValue.Value] |