【发布时间】:2012-11-08 14:54:29
【问题描述】:
我有一个List<List<string>>,其中外部列表是网格的行,内部列表是列值。
如何包装 List<List<string>> 使其成为网格的合适数据源,接受 IList 或 IBindingList?
实际上,我希望它被视为List<MyObject>,其中MyObject 类将字符串公开为用于绑定的公共属性。
我无法更改列表,而且它可能包含大量行,因此复制数据并不理想。
差异的一个简单示例是以下代码,其中DataGridView 放在WinForm 上:
public class SupplierEntry
{
public string SupplierCode
{
get
{
return "SUPPLIERCODE";
}
}
public string SupplierTitle
{
get
{
return "SUPPLIERTITLE";
}
}
}
private void Test()
{
List<string> supplierEntryString = new List<string>();
supplierEntryString.Add("SUPPLIERCODE");
supplierEntryString.Add("SUPPLIERTITLE");
List<List<string>> supplierListStrings = new List<List<string>>();
supplierListStrings.Add(supplierEntryString);
List<SupplierEntry> supplierListObjects = new List<SupplierEntry>();
SupplierEntry supplierEntryObject = new SupplierEntry();
supplierListObjects.Add(supplierEntryObject);
//this can't handle the nested collections, instead showing a Capacity and Count column
dataGridView1.DataSource = supplierListStrings;
//this works giving you a supplier code and title column
//dataGridView1.DataSource = supplierListObjects;
}
【问题讨论】:
-
“网格”是指DataGridView吗?
-
Infragistics UltraGrid 和 UltraCombo(丢弃的部分实际上也是一个网格)。
标签: c# winforms data-binding .net-4.0 infragistics