我有一个 DataGridView 如另一个问题 and AllowUserToDeleteRows
被设定为true
.
The docs比如说IBindingList.AllowRemove
还应该设置为true
。然而List好像没有那个接口,而且好像也没有need它。一can从列表中删除项目。
A 类似问题的答案建议设置DataGridView.EditMode
to EditOnKeystroke
。但这没有帮助。
那么 - 我怎样才能允许用户删除行?
我能够毫无问题地删除它:
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; }
}
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;
}
}
Result:
![enter image description here](https://i.stack.imgur.com/61wCl.png)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)