winForms + DataGridView binding to a List

后端 未结 4 871
夕颜
夕颜 2020-12-29 20:15

I\'m trying to bind a List to a DataGridView control, and I\'m not having any luck creating custom bindings.

I have tried:

gvPr         


        
4条回答
  •  甜味超标
    2020-12-29 20:16

    Another solution I've found is to use the BindingList collection.

    
    
    private void Form1_Load(object sender, EventArgs e)
    {
       BindingList people= new BindingList {
        new Person {Name="John",Age=23},
        new Person {Name="Lucy",Age=16}
      };
    
       dataGridView1.DataSource= people;
    }
    

    It works fine for me,

提交回复
热议问题