问题描述
我在GUI中有一个选项卡控件,并且其中一个选项卡中包含WPF 4.0数据网格。当我单击网格中的一个单元格并编辑内容然后切换选项卡时,出现了Defer Refresh错误:
I have a tab control in the GUI and there is WPF 4.0 datagrid in one of the tabs. When I click on a cell in the grid and edit something and then switch tabs, I get a Defer Refresh error:
所以我叫 datagrid.CancelEdit(DataGridEditingUnit.Row)
,当切换制表符以取消任何待处理的编辑并且Defer刷新问题消失了。
So I call datagrid.CancelEdit(DataGridEditingUnit.Row)
when tab is switched to cancel any pending edit and the Defer refresh issue is gone.
但是我真正想做的是 CommitEdit()
,以便用户不必再次输入数据。
But what I really want to do is CommitEdit()
so that the user doesn't have to reenter the data again.
和 datagrid.CommitEdit (DataGridEditingUnit.Row,是的)
对我不起作用。
我在 CommitEnd()
上收到以下错误:
And datagrid.CommitEdit(DataGridEditingUnit.Row, true)
doesn't work for me.I get the below error on CommitEnd()
:
PS:我尝试了datagrid.CommitEdit()和datagrid.CommitEdit (DataGridEditingUnit.Column,true),它没有用。
PS: I have tried datagrid.CommitEdit() and datagrid.CommitEdit(DataGridEditingUnit.Column, true) and it didnt work.
推荐答案
我通过为DataGrid的Unloaded事件添加以下处理程序来解决此问题:
I solved this by adding this handler for the DataGrid's Unloaded event:
void DataGrid_Unloaded(object sender, RoutedEventArgs e)
{
var grid = (DataGrid)sender;
grid.CommitEdit(DataGridEditingUnit.Row, true);
}
这篇关于在AddNew或EditItem事务期间不允许使用'DeferRefresh'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!