获取wpf datagrid当前被编辑单元格的内容

简介: 原文 获取wpf datagrid当前被编辑单元格的内容 确认修改单元个的值, 使用到datagrid的两个事件 开始编辑事件 BeginningEdit="dataGrid_BeginningEdit" 编辑结束事件 CellEditEnding="dataGrid_CellEditE...

原文 获取wpf datagrid当前被编辑单元格的内容

确认修改单元个的值,

使用到datagrid的两个事件

开始编辑事件

BeginningEdit="dataGrid_BeginningEdit"

编辑结束事件

CellEditEnding="dataGrid_CellEditEnding"

代码片段如下

复制代码
//开始修改时单元格内的值
string preValue = "";
private void dataGrid_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
{
//将修改前的值保存起来
preValue = (e.Column.GetCellContent(e.Row) as TextBlock).Text;
}

private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
string newValue = (e.EditingElement as TextBox).Text;
//如果修改后的值和修改前的值不一样
if (preValue != newValue)
{
//进一步操作
}
}
复制代码

 

目录
相关文章
|
2月前
|
前端开发 C#
浅谈WPF之DataGrid动态生成列
在日常开发中,DataGrid作为二维表格,非常适合数据的展示和统计。通常情况下,一般都有固定的格式和确定的数据列展示,但是在某些特殊情况下,也可能会需要用到动态生成列。本文以一些简单的小例子,简述在WPF开发中,如何动态生成DataGrid的行和列,仅供学习分享使用,如有不足之处,还请指正。
108 2
|
8月前
|
数据挖掘 数据处理 C#
WPF技术之DataGrid控件
WPF DataGrid是一种可以显示和编辑数据的界面控件。它可以作为表格形式展示数据,支持添加、删除、修改、排序和分组操作。
182 0
|
9月前
|
C#
让WPF中的DataGrid像Excel一样可以筛选(下)
让WPF中的DataGrid像Excel一样可以筛选(下)
125 0
|
9月前
|
前端开发 C# 数据库
让WPF中的DataGrid像Excel一样可以筛选(上)
让WPF中的DataGrid像Excel一样可以筛选(上)
119 0
让WPF中的DataGrid像Excel一样可以筛选(上)
|
9月前
|
C# 数据库
WPF中DataGrid控件绑定数据源
WPF中DataGrid控件绑定数据源
117 0
WPF 点击 Datagrid 中的TextBox 控件获取其所在行的数据
WPF 点击 Datagrid 中的TextBox 控件获取其所在行的数据
|
C#
WPF 4 DataGrid 控件(自定义样式篇)
原文:WPF 4 DataGrid 控件(自定义样式篇)      在《WPF 4 DataGrid 控件(基本功能篇)》中我们已经学习了DataGrid 的基本功能及使用方法。本篇将继续介绍自定义DataGrid 样式的相关内容,其中将涉及到ColumnHeader、RowHeader、Row、Cell 的各种样式设置。
2466 0
|
C# 前端开发
wpf中的datagrid绑定操作按钮是否显示或者隐藏
如图,需要在wpf中的datagrid的操作那列有个确认按钮,然后在某些条件下确认按钮可见,某些情况下不可见的,放在mvc里直接在cshtml页面中if..else就行了。 但是在wpf里不行。。网上搜索了好久才找到解决方法,原来只是binding那个visiable属性就行了,
6847 0
|
C#
WPF 4 DataGrid 控件(基本功能篇)
原文:WPF 4 DataGrid 控件(基本功能篇)      提到DataGrid 不管是网页还是应用程序开发都会频繁使用。通过它我们可以灵活的在行与列间显示各种数据。本篇将详细介绍WPF 4 中DataGrid 的相关功能。
1447 0
|
C#
WPF 4 DataGrid 控件(进阶篇二)
原文:WPF 4 DataGrid 控件(进阶篇二)      上一篇《WPF 4 DataGrid 控件(进阶篇一)》中我们通过DataGridTemplateColumn 类自定义编辑了日期列的样式,当然也可以根据个人需要设置任何样式模板。
1042 0