c# - WPF DataGrid - 编辑结束后单元格的新值

标签 c# .net wpf datagrid

在我的系统中,我需要捕获并发送单元格编辑的旧值和新值。我读过,您可以通过像这样检查事件 DataGridCellEditEndingEventArgs 的 EditingElement 来做到这一点:

    _dataGrid.CellEditEnding += (sender, e) => {
      var editedTextbox = e.EditingElement as TextBox;

      if (editedTextbox != null)
      MessageBox.Show("Value after edit: " + editedTextbox.Text);
}

在我的例子中,数据是一个字典,所以 EditingElement 是一个 ContentPresenter

var editedTextbox = e.EditingElement as ContentPresenter;
if (editedTextbox != null)
  MessageBox.Show("Value after edit: " + editedTextbox.Content);

并且内容是原始值,而不是新编辑的值。

我怎样才能让它工作:

_dataGrid.SomeEvent(sender, e)->{
  SendValues(e.oldCellValue, e.newCellValue);
}

最佳答案

我采用了让我的行数据对象继承自 IEditableObject 的方法。我在 EndEdit() 接口(interface)方法中处理更新的值

关于c# - WPF DataGrid - 编辑结束后单元格的新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28156929/

相关文章:

c# - 获取两次之间的记录列表 C# Linq To Entities

C# - 从 C# 应用程序向 Google Chrome 发送消息

c# - 如何使用 JSON.Net 获取反序列化 json 的 key

c# - 使用 MediaElement 的 WPF 音频播放器有时会滞后

c# - 如何在显示应用程序主窗口之前运行可执行文件?

c# - 如何从列表框中的项目访问复选框

c# - C# 中的 Word 自动化。使用另存为时出错

.net - 无法加载 DLL 'SqlServerSpatial140.dll' : The specified module could not be found

c# - DataGridView.Editmode = EditOnEnter。如何选择要删除的行?

C#。缩短标识符名称是否会提高应用程序的整体运行时性能?