外側のリストが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;
}