【发布时间】:2015-02-21 06:09:18
【问题描述】:
我有一个 WPF DataGrid,我通过双击它来编辑一个单元格,这通常可以工作。
但如果我在单元格中处于编辑模式,然后用鼠标单击不同的行,则编辑将不会存储在单元格中。它是空的。
但是我用鼠标点击同一行中的另一个单元格 - 单元格值将正确显示。
<DataGrid ItemsSource="{Binding Items, Mode=TwoWay}"
SelectionMode="Single"
CanUserAddRows="False"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
CellEditEnding="DataGrid_OnCellEditEnding">
<DataGrid.Columns>
<DataGridTextColumn Header="Test"
Binding="{Binding Path=SomeValue, Mode=TwoWay, ValidatesOnExceptions=True, StringFormat=d, TargetNullValue={x:Static sys:String.Empty}}" />
</DataGrid.Columns>
</DataGrid>
代码隐藏
private void DataGrid_OnCellEditEnding(object sender, DataGridCellEditEndingEventArgs e) {
//save the changes in the DB
}
这是怎么回事?
【问题讨论】:
-
在更改单元格值时,您是否还更改了与数据网格绑定的itemsource Items?
-
不,我不会那样做。
-
这可能是原因。您的数据网格与Itemsource绑定,并且datagrid要求Itemsource被chaged。
-
好的,我去看看。
-
我很确定,这将解决您的问题。 ..
标签: c# wpf events mvvm datagrid