简体   繁体   中英

Defining a List and then Binding to a Data Grid View

I am attempting to define a list and then assign it to a Data Grid View:

    var list = new[]
{ 
    new { Number = 10, Name = "Smith" },
    new { Number = 10, Name = "John" } 
}.ToList();

var bindingList = new BindingList(list);
var source = new BindingSource(bindingList, null);
dgvResult.DataSource = source;

I know my problems stem from new BindingList(list) - do I need to define the type?

Why the BindingList? Following code works:

    var list = new[]
    {   
        new{Number = 10, Name="John"},
        new {Number=20, Name="Smith"}
    }.ToList();

    dataGridViewList.DataSource = list;

Hopefully it helps...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM