Using the DataBinding property in the TableVectorGroup, which is the base class for table row and column groups, a RenderTable can be data bound.
For examples of binding to a RenderTable, see the DataBinding sample installed in the ComponentOne Samples folder.
Note that not only groups of rows, but also groups of columns can data bound. That is, a table can grow not only down, but also sideways.
Grouping will work, but note that group hierarchy is based on the hierarchy of TableVectorGroup objects, as shown in the following code:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim rt As C1.C1Preview.RenderTable = New C1.C1Preview.RenderTable rt.Style.GridLines.All = C1.C1Preview.LineDef.Default ' Table header: Dim c As C1.C1Preview.TableCell = rt.Cells(0, 0) c.SpanCols = 3 c.Text = "Header" ' Group 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 ' Sub-group header: 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 ' Sub-group data: 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]" ' Create a group of data bound lines, grouped by the GroupId field: 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 ' Create a nested group, grouped by 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 ' Create yet deeper nested data bound group: Dim ng2 As C1.C1Preview.TableVectorGroup = rt.RowGroups(3, 1) ng2.DataBinding.DataSource = g.DataBinding.DataSource ng2.Style.BackColor = Color.LightSteelBlue |
To write code in C#
C# |
Copy Code
|
---|---|
RenderTable rt = new RenderTable(); rt.Style.GridLines.All = LineDef.Default; // Table header: TableCell c = rt.Cells[0, 0]; c.SpanCols = 3; c.Text = "Header"; // Group 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; // Sub-group header: 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; // Sub-group data: 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]"; // Create a group of data bound lines, grouped by the GroupId field: 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; // Create a nested group, grouped by 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; // Create yet deeper nested data bound group: TableVectorGroup ng2 = rt.RowGroups[3, 1]; ng2.DataBinding.DataSource = g.DataBinding.DataSource; ng2.Style.BackColor = Color.LightSteelBlue; |
The above code can be illustrated by the following table:
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] |