C#WinForms BindingList&;DataGridView-不允许编辑会阻止创建新行吗?我如何解决这个问题?
关于将DataGridView与BindingList一起使用,我将禁用编辑当前行,但允许添加新行。我遇到的问题是,当我不允许编辑时,这似乎会阻止添加新行项,因为当您将表格放入单元格中以获取新行时,它似乎不允许编辑 你知道怎么避开这个吗?我的代码的以下部分:C#WinForms BindingList&;DataGridView-不允许编辑会阻止创建新行吗?我如何解决这个问题?,c#,winforms,data-binding,datagridview,bindingsource,C#,Winforms,Data Binding,Datagridview,Bindingsource,关于将DataGridView与BindingList一起使用,我将禁用编辑当前行,但允许添加新行。我遇到的问题是,当我不允许编辑时,这似乎会阻止添加新行项,因为当您将表格放入单元格中以获取新行时,它似乎不允许编辑 你知道怎么避开这个吗?我的代码的以下部分: BindingSource bs = new BindingSource(); bList = new BindingList<Customer>(); bList.AllowNew = true; bL
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;
BindingSource bs=newbindingsource();
bList=新绑定列表();
bList.AllowNew=真;
bList.AllowEdit=false;
//用顾客填满bList
b添加(新客户(“Ted”);
添加(新客户(“Greg”);
bList.Add(新客户(“John”));
bs.DataSource=bList;
dataGridView1.DataSource=bs;
谢谢与其与源代码抗争,不如请
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;
};
(并且不要在列表上设置允许它
)