Make List <list <string>&gt;适合绑定</list <string>

时间:2012-11-08 14:54:30

标签: c# winforms data-binding .net-4.0 infragistics

我有一个List<List<string>>,其中外部列表​​是网格的行,内部列表是列值。

如何打包List<List<string>>以使其成为网格的合适数据源,接受IListIBindingList

实际上我希望它被视为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;
    }

0 个答案:

没有答案