WPF 数据网格行编辑“已结束”事件
我知道 WPF datagrid 有“RowEditEnding”事件,但我需要在 Row 承诺检查新添加的行是否重复并合并重复的行后触发该事件。我的数据网格将“CanUserAddRow”属性设置为 True。
我正在使用 EntityObservableCollection 扩展 ObservableCollection 将我的实体与集合同步。因此,我考虑了 OnCollectionChanged 事件,但是一旦用户单击新项目占位符行,就会引发“InsertItem”事件,这意味着该对象仍然是空的,我无法检查重复项。
无论如何,我可以引发 RowEditEnded 事件吗?
谢谢...
I know that WPF datagrid has "RowEditEnding" event , but I need to fire the event on after the Row has comitted to check if the newly added row is duplicated and merge the duplicated row. My datagrid has "CanUserAddRow" property set to True.
I am using EntityObservableCollection that extends ObservableCollection to synchronize my entity with the collection. So, i considered OnCollectionChanged event, but the "InsertItem" event is raise once user click on the new item place holder row, which means the object is still empty and I cant check for duplicate.
Is there anyway that I can raise the RowEditEnded event?
Thanks...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您可以在数据网格的属性成员绑定上使用
UpdateSourceTrigger=PropertyChanged
。这将确保当CellEditEnding
被触发时,更新已经反映在可观察集合中。请参阅这篇文章https://stackoverflow.com/a/27239243/9285072
You can use
UpdateSourceTrigger=PropertyChanged
on the binding of the property member for the datagrid. This will ensure that whenCellEditEnding
is fired the update has already been reflected in the observable collection.see this post https://stackoverflow.com/a/27239243/9285072
找到了您的问题的答案
我使用 VS2010 RowEditEnding 中的 if (e.EditAction == DataGridEditAction.Commit) 条件将满足您的要求
请参阅下面的代码。
这就是背后的Xaml。
I found an answer to your question usingVS2010
condition if (e.EditAction == DataGridEditAction.Commit) in the RowEditEnding will fulfill ur requirement
Please see the below code.
This is the Xaml Behind.
从 @MaherBenIssa 的回答中,我用它来避免添加和删除委托:
Taking from @MaherBenIssa's answer, I used this to avoid add and remove delegate:
尝试为您的数据网格设置 CommitEdit() 函数。我在这里使用它:
Try setting the CommitEdit() function for your datagrid. I used it here:
VB.NET解决方案@MaherBenIssa的解决方案
VB.NET solution to the solution of @MaherBenIssa
也许您可以使用事件“CurrentCellChanged”。当您开始编辑单元格时也会触发此事件,但也许您可以找到一种方法来不总是在您的方法中执行您想要执行的所有操作。
当我想检查数据网格中的更改是否实际上是对原始值的更改时,我遇到了同样的问题。这个活动正在满足我的需求。
希望我能告诉你一些新的东西。
Maybe you can use the event "CurrentCellChanged". This fires when you start editing a cell too, but maybe you can find a way to not always do everything you want to do in your method.
I had same problem when i wanted to check if the changes in the datagrid are actually changes to the original values. This event is working for my needs.
Hope i could tell you something new.
我想知道为什么你要找到引发 RowEditEnded 事件的方法;
如果你实现datagrid的RowEditEnding事件;每当您编辑一行并更改该行的焦点时,都会提交该行并引发 RowEditEnding;
因此,在 Row 提交后,RowEditEnding 将被引发并像 RowEditEnded 一样工作;
我从您的文字中理解有误吗?
I wonder why you are finding the way to raise the RowEditEnded event;
if you Implement the RowEditEnding event of datagrid; whenever you edited a row and change the focus from that row, the row will be committed and RowEditEnding will be raised;
so after the Row has committed RowEditEnding will be raised and work just as RowEditEnded;
Did I understand something wrong from your text?