WPF 将 DataGrid 中的更改保存到 DataTable
我的应用程序要求将 WPF DataGrid
控件中所做的更改保存回 DataTable
。我已成功将数据从 DataGrid
保存到 DataTable
,但是,从 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();
}
}
这有效,但它不保存更改,它只是将 DataRow
保存为在 DataGrid
中更改之前的状态。
我错过了什么吗?
My application requires that changes made in the WPF DataGrid
control are saved back to the DataTable
. I have managed to save data from the DataGrid
to DataTable
, however, the data saved from the DataGrid
does not show the changes I have made, it just shows the data that was already there when the DataGrid
was first populated.
I have got this far:
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();
}
}
This works but it does not save the changes, it just saves the DataRow
as it was before it was changed in the DataGrid
.
Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
终于找到答案了!我必须获取正在更改的
DataRow
:Finally found the answer!. I have to Get the
DataRow
that was being changed:您需要在完成后调用 AcceptChanges你的改变。
You need to call AcceptChanges after you make your changes.