检查 ObservableCollection 是否有效
我有一个 WPF Dev Express DxGrid,它通过以下方式绑定到 ObservableCollection。
Private _FamilyList As New ObservableCollection(Of FamilyRecord)
MyGrid.DataSource = _FamilyList
当用户开始在网格中输入信息时,我需要能够检查他们是否错过了某些信息,从而使其无效。
那么,检查 _FamilyList 没有验证错误的最佳方法是什么?
I have a WPF Dev Express DxGrid that is bound to an ObservableCollection in the following way.
Private _FamilyList As New ObservableCollection(Of FamilyRecord)
MyGrid.DataSource = _FamilyList
When a user starts to enter information in the grid, I need to be able to check whether they have missed some information making it Invalid.
So, what is the best method of checking that the _FamilyList has no validation errors?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有 DevExpress 网格的经验,但在 Xceed WPF DataGridControl 上有一个名为
UpdateSourceTrigger
的属性,它控制数据源何时更新(当用户完成编辑整行时,完成)编辑单元格,或每次击键)。我确信 DevExpress 也有类似的概念。这将使您能够控制验证发生的时间。您可以将数据验证逻辑放在
FamilyRecord
类本身中。当您检测到错误时,将FamilyRecord
置于错误状态,该状态将在网格中提供视觉提示。编辑:
要在保存时确定集合中的任何
FamilyRecord
对象是否有任何错误,您需要如下所示:I don't have experience w/ the DevExpress grid, but on the Xceed WPF DataGridControl there's a property called
UpdateSourceTrigger
which controls when the data source gets updated (when the user is finished editing an entire row, finished editing a cell, or with every key stroke). I'm sure DevExpress has a similar concept.This will give you control over when the validation happens. You can put your data validation logic in the
FamilyRecord
class itself. When you detect an error put theFamilyRecord
into an error state that will provide a visual cue in the grid.EDIT:
To determine, upon saving, whether any
FamilyRecord
objects in your collection have any errors you'd want something like this: