【发布时间】:2016-08-07 03:49:09
【问题描述】:
我有一个绑定到 DataTable 'ExcludedMachines' 的 DataGridView 'DGV_MachinesExclusion'。在 DataGridView 中手动添加新行时,我使用 DataGridView 的 CellValueChanged 事件来触发下面的代码。
private void DGV_MachinesExclusion_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
DataRow dr = ExcludedMachines.NewRow();
dr = ((DataRowView)DGV_MachinesExclusion.Rows[0].DataBoundItem).Row;
ExcludedMachines.Rows.Add();
UpdateExlusionList();
}
结果是它增加了两行。一行空白,一行手动添加数据。 'UpdateExclusionList()' 方法只是将 DataTable 写入 XML 文件。 我过去曾使用这种方式成功地动态添加行。谁能解释为什么这段代码添加了两行?
谢谢,托马斯
【问题讨论】:
标签: c# data-binding datagridview datatable