如何禁止在我的 DataGrid 中添加不完整的行?
我有一个绑定到对象集合的 DataGrid(当前为 .NET 3.5 WPFToolkit 版本,但如果需要,我可以使用 .NET 4.0 开箱即用的 DataGrid)。数据网格中的三列代表用作从数据库中获取其他信息的键的信息片段。这些其他信息用于计算以填充数据网格的其他列。
一旦用户输入这三个字段,并且这些字段中的数据组合存在于数据库中,则该行被认为是有效的,可以添加到集合中。用户现在还可以自由编辑该行中的其他列。一旦用户向任何其他列提供数据,三个“关键”字段就被视为“锁定” - 用户不能再编辑它们。更改该信息的唯一方法是删除整行并添加新行。
1)从用户体验的角度来看,处理这个问题的最佳方法是什么?我是否应该允许用户在任何列中输入数据,“缓存”他们的条目,然后仅在输入“关键”数据后立即进行所有计算?或者我应该限制用户只能先输入“关键”数据,然后允许用户在其他列中输入数据?
2)在数据网格中实现上述内容的策略是什么(我需要的事件处理程序等)?如何不允许将新行添加到数据绑定集合中,直到它具有有效的“关键”数据,或者我是否允许添加带有验证错误的新行并以某种方式跟踪用户可以继续编辑部分完成的行的“关键”列,但不编辑数据网格中的其他现有行?
I have a DataGrid (currently the .NET 3.5 WPFToolkit version, but I can use the .NET 4.0 out-of-the-box DataGrid if needed) bound to a collection of objects. Three of the columns in the data grid represent pieces of information used as a key to grab other information from the database. This other information is used in calculations to populate other columns of the data grid.
Once the user enters these three fields, and the combination of the data in those fields exists in the database, the row is considered valid for adding to collection. The user is also now allowed to freely edit the other columns in the row. Once any other column is given data by the user, the three "key" fields are considered "locked" - the user may no longer edit them. The only way to change that information is to delete the entire row and add a new row.
1) What is the best way from a UX perspective to handle this? Should I allow the user to enter data in any column, "cache" their entries, then do my calculations all at once only after the "key" data is entered? Or should I restrict the user to only enter the "key" data first, then allow the user to enter data in the other columns?
2) What is the strategy (event handlers I need, etc.) for implementing the above in the data grid? How do I not allow the new row to be added to the data bound collection until it has valid "key" data, or do I allow the new row to be added with validation errors and somehow track that it is ok for the user to continue editing the "key" columns of the partially complete row, but not other existing rows in the data grid?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是我针对我的特殊情况所做的:
1)处理此问题的最佳方法是为用户提供最大的灵活性。这意味着允许用户在一定条件下编辑关键数据,但不限制用户首先输入关键数据。
2)实施策略分为两部分。首先,定义何时不允许用户再编辑关键数据,并向数据网格列添加样式,根据触发器将键值列切换为只读模式。其次,当关键数据更改时,执行所有幕后逻辑,就好像使用旧关键数据删除该行,然后使用新关键数据创建该行一样。这将涵盖我需要发生的所有副作用。
This is what I did for my particular situation:
1) The best way to handle this is to give the user the most flexibility possible. This means allowing the user to edit the key data under certain conditions, but not restricting the user to entering key data first.
2) The strategy for implementing that has two parts. First, define when the use is not allowed to edit the key data anymore, and add styles to the datagrid columns that switch the key value columns to a read-only mode based on a trigger. Second, when key data is changed, perform all of the logic behind-the-scene as if the row were deleted using the old key data and then created using the new key data. This will cover all of the side-effects I need to have happen.