1

我的应用程序要求将 WPF 控件中所做的更改DataGrid保存回DataTable. 我已经设法将数据从 保存DataGridDataTable,但是,从 保存的数据DataGrid没有显示我所做的更改,它只显示了DataGrid第一次填充时已经存在的数据。

我已经做到了这一点:

public void UpdateQueueData(object sender, DataGridRowEditEndingEventArgs e)
 {
     if (e.EditAction == DataGridEditAction.Commit)
     {
         DataGridRow dgRow = e.Row;
         DataRowView rowView = dgRow.Item as DataRowView;
         DataRow drItem = rowView.Row;
         Queue.Rows.RemoveAt(e.Row.GetIndex());
         Queue.ImportRow(drItem);
         WriteXML();
     }
 }

这有效,但它不会保存更改,它只是DataRowDataGrid.

我错过了什么吗?

4

2 回答 2

2

终于找到答案了!。我必须得到DataRow正在改变的东西:

private void dataGrid_CurrentCellChanged(object sender, EventArgs e)
{
    DataTable dt = ((DataView)dataGridQueue.ItemsSource).ToTable();
    // Set the value of my datatable to the the changed version before 
    // writing it so a file.
    dt.WriteXMLScema(...);
}
于 2009-12-10T09:44:38.953 回答
0

进行更改后,您需要调用AcceptChanges 。

于 2009-12-09T06:13:37.070 回答