2009-12-09 30 views
0

我的应用程序要求将WPF DataGrid控件中所做的更改保存回DataTable。我已经成功地将DataGrid中的数据保存到DataTable,但从DataGrid保存的数据未显示我所做的更改,它仅显示DataGrid首次填充时已存在的数据。WPF将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(); 
    } 
} 

这工作,但它不保存更改,它只是保存DataRow,因为它是它在DataGrid改变之前。

我错过了什么吗?

回答

1

终于找到答案了!我得在

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(... 
    } 
0

是否在您做出更改后致电AcceptChanges

+0

遗憾的是变更后的DataRow的,我的意思是在DataGrid中所做的更改均没有出现在DataRow中:drItem时正在触发事件。 – 2009-12-10 00:55:28

相关问题