我的建议是将列表转换为DataTable,然后使用表的默认视图构建您的DataView.
首先,你必须建立数据表:
// is the type of data in the list.
// If you have a List, for example, then call this as follows:
// List ListOfInt;
// DataTable ListTable = BuildDataTable(ListOfInt);
public static DataTable BuildDataTable(IList lst)
{
//create DataTable Structure
DataTable tbl = CreateTable();
Type entType = typeof(T);
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(entType);
//get the list item and add into the list
foreach (T item in lst)
{
DataRow row = tbl.NewRow();
foreach (PropertyDescriptor prop in properties)
{
row[prop.Name] = prop.GetValue(item);
}
tbl.Rows.Add(row);
}
return tbl;
}
private static DataTable C