[英]C# WinForms BindingList & DataGridView - disallowing EDIT prevents creation of a NEW row? How can I address this?
Regarding my use of a DataGridView with BindingList, I was to disable editing current rows, but allow adding new rows. 关于将DataGridView与BindingList一起使用,我将禁用编辑当前行,但允许添加新行。 The issue I have is that when I disallows edits, this seems to prevent one from adding a new row item, as when you table into the cell for this new row it does not seem to allow editing???
我的问题是,当我禁止编辑时,这似乎阻止了它添加新的行项目,因为当您将表格插入该新行的单元格时,它似乎不允许编辑?
Know how to get around this? 知道如何解决这个问题? Section of my code below:
我的代码部分如下:
BindingSource bs = new BindingSource();
bList = new BindingList<Customer>();
bList.AllowNew = true;
bList.AllowEdit = false;
// Fill bList with Customers
bList.Add(new Customer("Ted"));
bList.Add(new Customer("Greg"));
bList.Add(new Customer("John"));
bs.DataSource = bList;
dataGridView1.DataSource = bs;
thanks 谢谢
Rather than fight the source, perhaps ask the DataGridView
to officiate: 与其争用源代码,不如要求
DataGridView
主持:
dataGridView1.DataSource = bs;
dataGridView1.ReadOnly = true;
dataGridView1.CurrentCellChanged += delegate
{
DataGridViewRow row = dataGridView1.CurrentRow;
bool readOnly = row == null ||
row.Index != dataGridView1.NewRowIndex;
dataGridView1.ReadOnly = readOnly;
};
(and don't set AllowEdit
on the list) (并且不要在列表上设置
AllowEdit
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.