Wah*_*tar 13 .net c# datagridview bindinglist winforms
我已经DataGridView
是必然DataSource
的List<myClass>
.但是当我将" AllowUserToAddRows
"属性设置为"True"时,没有任何东西出现.
我试图改变true
到DataSource
,它的顺利.
我不知道我是否应该取代我BindingList<myClass>
与List<>
或有更好的解决方案.
Mar*_*ell 22
是否myClass
有一个公共的无参数构造函数?如果没有,您可以派生BindingList<T>
并覆盖AddNewCore
以调用您的自定义构造函数.
(编辑)或者 - 只需将您的列表包装在一个BindingSource
,它可能会工作:
using System;
using System.Windows.Forms;
using System.Collections.Generic;
public class Person {
public string Name { get; set; }
[STAThread]
static void Main() {
var people = new List<Person> { new Person { Name = "Fred" } };
BindingSource bs = new BindingSource();
bs.DataSource = people;
Application.Run(new Form { Controls = { new DataGridView {
Dock = DockStyle.Fill, DataSource = bs } } });
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10097 次 |
最近记录: |