我的动机是使用某种数据绑定/数据源(因为它在DataGridView中使用,ListView by .Net FrameWork)用于我自己的自定义对象 AdvancedTableEntries with < EM> BindingList<Employee>
我的BindingList对象
public class Employee
{
public string Name{get;set;}
public int PayrollRollNo{get;set;}
public Address CurrentAddress{{get;set;}}
}
如何实现方法GetTableEntries()?
class CustomTable : : AdvancedTable
{
IList<Employee> EmployeeItems;
public CustomTable(IList<Employee> items)
{
EmployeeItems = items;
}
public override void CreateDefaultColumns()
{
Columns.Add(new AdvancedTableColumn
{
Visible = true,
DataPropertyName = "Name",
FillWeight = 2,
Merging = true,
});
Columns.Add(new AdvancedTableColumn
{
Visible = false,
HeaderText = Localization.Common.Name,
DataPropertyName = "PayrollRollNo",
FillWeight = 2,
SomeFancyFunction = delegate (object item)
{
var item2 = item as Employee;
return some fancy things...
}
});
}
public override AdvancedTableEntries GetTableEntries()
{
//How to get entries as comparing "DataPropertyName"?and do something like this:
List<AdvancedTableCell[]> tableEntries.DataSource= EmployeeItems;
// Or as AdvancedTableEntries
}
}
我的自定义对象作为最终结果
public class AdvancedTableEntries
{
public AdvancedTableEntries(List<AdvancedTableColumn> columns, List<AdvancedTableCell[]> tableEntries)
{
Columns = columns;
TableEntries = tableEntries;
int width = tableEntries.First().Length;
if (!width.Equals(columns.Count)) throw new System.ArgumentException("Report Entry Column and Datacolumn size doesnot match", "EntriesData");
}
public List<AdvancedTableColumn> Columns { get; private set; }
public List<AdvancedTableCell[]> TableEntries { get; private set; }
}
//预期表格结果为:
Name PayRollNo
John 12345
Harry 4567
Trumph 0000