C# 为什么我';我在删除DataGridView控件中的行时遇到此错误?

C# 为什么我';我在删除DataGridView控件中的行时遇到此错误?,c#,winforms,C#,Winforms,为什么在删除DataGridView控件中的行时出现此错误? 我如何解决这个问题 Rows cannot be programmatically removed unless the DataGridView is data-bound to an IBindingList that supports change notification and allows deletion. 公共部分类表单1:表单 { 列表人员=新列表(); 公共表格1() { 初始化组件(); } void For

为什么在删除DataGridView控件中的行时出现此错误? 我如何解决这个问题

Rows cannot be programmatically removed unless the DataGridView is data-bound to an IBindingList that supports change notification and allows deletion.

公共部分类表单1:表单
{
列表人员=新列表();
公共表格1()
{
初始化组件();
}
void Form1Load(对象发送方,事件参数e)
{
添加(新的人(“麦当劳”、“罗纳德”));
添加(新人物(“罗杰斯”、“肯尼”);
dataGridView1.DataSource=个人;
}
void BtnDeleteClick(对象发送者,事件参数e)
{
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].索引);
}
}
列表
未实现
IBindingList

public class List<T> : IList<T>, ICollection<T>, 
    IEnumerable<T>, IList, ICollection, IEnumerable
公共类列表:IList、ICollection、,
IEnumerable,IList,ICollection,IEnumerable
您需要使用实现
IBindingList


使用or,您必须从
人员
列表中删除一个元素

person.RemoveAt(0);
我的解决方案:

void BtnDeleteClick(object sender, EventArgs e)
{
    person.RemoveAt(dataGridView1.SelectedRows[0].Index);
}

所以,我不是要列表,而是要让它成为绑定列表吗?谢谢你们和谷歌。现在遇到了这个错误:)非常感谢你给我这个救命的答案。
void BtnDeleteClick(object sender, EventArgs e)
{
    person.RemoveAt(dataGridView1.SelectedRows[0].Index);
}