Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# AllowUserToAddress不';无法使用列表<&燃气轮机;DataGridView上的数据源_C#_.net_Winforms_Datagridview_Bindinglist - Fatal编程技术网

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});
}
}