我能沒有問題將其刪除:
private void Form1_Load(object sender, EventArgs e)
{
myDataListBindingSource.DataSource = new MyDataList();
}
public class MyDataList : List<MyData>
{
public MyDataList()
{
Add(new MyData { ID = 1, Name = "Name 1" });
Add(new MyData { ID = 2, Name = "Name 2" });
Add(new MyData { ID = 3, Name = "Name 3" });
Add(new MyData { ID = 4, Name = "Name 4" });
Add(new MyData { ID = 5, Name = "Name 5" });
}
}
public class MyData
{
public int ID { get; set; }
public string Name { get; set; }
}
編輯:或者,如果你想要做手工,而不使用VS設計師
public partial class Form1 : Form
{
BindingSource myDataListBindingSource;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
myDataListBindingSource = new BindingSource();
myDataListBindingSource.DataSource = new MyDataList();
dataGridView1.DataSource = myDataListBindingSource;
}
}
結果:
可能重複的[Dat aGridView刪除行時,數據源是列表](http://stackoverflow.com/questions/21572273/datagridview-delete-row-when-datasource-is-listmyclass) –
manji