具有绑定数据源commitedit()的Datagridview无法正常工作。
我正在为我的datagridview使用绑定列表<> / binding数据源。我可以编辑datagridview,但不能在表单视图上提交更改。 我正在使用commitedit()对gridview进行更改。但这行不通。 我无法以编程方式或在缓存中更改数据网格。
private void RichTextBox1_Enter(object sender, EventArgs e) {
private BindingList < string > attrNew = new BindingList < string > ();
attrNew.AllowEdit = true;
attrNew.AllowNew = true;
// attributes.CopyTo(0,attrNew.ToArray(),0,attributes.Count());
attributesBindingSource.DataSource = (from b in attrNew.Distinct().Select(a = >a.Split(new string[] {
" "
},
StringSplitOptions.RemoveEmptyEntries))
select new {
Field = b.GetValue(0) as string,
Attributes = b.GetValue(1) as string,
Value = b.GetValue(2) as string
}).ToList();
dataGridView1.DataSource = attributesBindingSource;
dataGridView1.EditMode = Lab.DataGridViewEditMode.EditOnEnter;
dataGridView1.ReadOnly = false;
while (count < dataGridView1.Rows.Count) {
dataGridView1.Rows[count].Cells["Field"].ReadOnly = false;
dataGridView1.Rows[count].Cells["Attributes"].ReadOnly = false;
dataGridView1.Rows[count].Cells["Value"].ReadOnly = false;
count++;
}
}
// This event handler manually raises the CellValueChanged event
// by calling the CommitEdit method.
void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e) {
dirty = true;
newValue = dataGridView1.EditingControl.Text;
if (dataGridView1.IsCurrentCellDirty) {
dataGridView1.CommitEdit(Lab.DataGridViewDataErrorContexts.Commit);
}
}
期望datagridview在编辑时反映出网格视图中的变化。