爲什麼我在DataGridView控件中刪除一行時出現此錯誤? 我該如何解決這個問題?爲什麼我在DataGridView控件中刪除一行時出現此錯誤?
Rows cannot be programmatically removed unless the DataGridView is data-bound to an IBindingList that supports change notification and allows deletion.
public partial class Form1 : Form
{
List<Person> person = new List<Person>();
public Form1()
{
InitializeComponent();
}
void Form1Load(object sender, EventArgs e)
{
person.Add(new Person("McDonalds", "Ronald"));
person.Add(new Person("Rogers", "Kenny"));
dataGridView1.DataSource = person;
}
void BtnDeleteClick(object sender, EventArgs e)
{
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
}
}
,這樣不是List,我必須做什麼事情的BindingList ? –
yonan2236
是的。這應該工作。 –
謝謝你和谷歌。剛剛遇到這個錯誤:) – Latheesan