WPF保存DataGrid中的变化到DataTable。

问题描述 投票:0回答:2

我的应用程序要求在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();
     }
 }

但它并没有保存更改,只是保存了... ... DataRow 如同在《公约》中改变之前一样 DataGrid.

我是不是遗漏了什么?

c# wpf datagrid datatable data-transfer
2个回答
1
投票

终于找到答案了!。我必须要获取正在改变的DataRow,在这个过程中,我必须要把数据保存到DataTable中,但是,我必须要把数据从DataGrid中保存到DataTable中。

 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
投票

你要打电话 接受更改 在您进行修改后。

© www.soinside.com 2019 - 2024. All rights reserved.