C# AllowUserToAddress不';无法使用列表<&燃气轮机;DataGridView上的数据源
我有一个C# AllowUserToAddress不';无法使用列表<&燃气轮机;DataGridView上的数据源,c#,.net,winforms,datagridview,bindinglist,C#,.net,Winforms,Datagridview,Bindinglist,我有一个DataGridView,其中DataSource设置为List 但是,当我将allowUserToAddress设置为true时,新行指示器不显示 当我将DataSource设置为bindingslist时,似乎解决了问题 问:应该用BindingList替换我的List,还是有更好的解决方案?myClass是否有公共无参数构造函数?如果没有,您可以从BindingList派生并重写AddNewCore来调用自定义构造函数 (编辑)或者-只需将列表包装在一个BindingSource中
DataGridView
,其中DataSource
设置为List
但是,当我将allowUserToAddress
设置为true
时,新行指示器不显示
当我将DataSource
设置为bindingslist
时,似乎解决了问题
问:应该用
BindingList
替换我的List
,还是有更好的解决方案?myClass是否有公共无参数构造函数?如果没有,您可以从BindingList
派生并重写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 } } });
}
}
使用系统;
使用System.Windows.Forms;
使用System.Collections.Generic;
公共阶层人士{
公共字符串名称{get;set;}
[状态线程]
静态void Main(){
var people=新列表{new Person{Name=“Fred”};
BindingSource bs=新的BindingSource();
bs.DataSource=人;
运行(新窗体{Controls={new DataGridView{
Dock=DockStyle.Fill,DataSource=bs});
}
}