我有一个DataGridView
与DataSource
set to List<myClass>
但是,当我设置时,新行指示器不显示AllowUserToAddRows
to true
,
当我设置DataSource
to BindingList<myClass>
,这似乎解决了问题。
Q: 应该取代我的List<>
with BindingList<>
或者有更好的解决方案?
Does 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 } } });
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)