下面代码实现得效果如图:
有两个问题,
1.如果数据源中有两个 list 对象,我只想让一个list 对象作为子表显示,另一个不显示。如果和设置.
2.如何批量设置子表中得列头和绑定得列?GetChildView现在只能一行一行得设置。
List<Student> a = new List<Student>();
for (int i = 0; i < 5; i++)
{
List<Marks> b = new List<Marks>();
for (int j = 0; j < 3; j++)
{
b.Add(new Marks() { Subject = "Subject i=" + i.ToString() + " j=" + j.ToString() });
}
a.Add(new Student() { StudentID = i, Name = i.ToString(), Performance = b });
}
spdDspQuery1.ActiveSheet.DataAutoSizeColumns = false;
spdDspQuery1.ActiveSheet.DataAutoCellTypes = false;
spdDspQuery1.ActiveSheet.AutoGenerateColumns = true;
spdDspQuery1.ActiveSheet.DataAutoHeadings = false;
spdDspQuery1.ActiveSheet.DataSource = a;
spdDspQuery1.ActiveSheet.Columns.Count = 2;
spdDspQuery1.ActiveSheet.Columns[0].DataField = "StudentID";
spdDspQuery1.ActiveSheet.ColumnHeader.Cells[0, 0].Value = "编号";
spdDspQuery1.ActiveSheet.Columns[1].DataField = "Name";
spdDspQuery1.ActiveSheet.ColumnHeader.Cells[0, 1].Value = "名字";
//创建的子表单。
spdDspQuery1.ActiveSheet.SetChildVisible(spdDspQuery1.ActiveSheet, true);
spdDspQuery1.ActiveSheet.GetChildView(0, 0).Columns.Count = 1;
spdDspQuery1.ActiveSheet.GetChildView(0, 0).Columns[0].DataField = "Subject";
spdDspQuery1.ActiveSheet.GetChildView(0, 0).ColumnHeader.Cells[0, 0].Value = "科目";
|