检查 DataGrid 的单元格当前是否已编辑的代码
是否有一个简单的可能性来检查DataGrid当前是否处于EditMode(无需订阅BeginningEdit和CellEditEnding)
Is there a simple possibility to check if the DataGrid is currently in EditMode (Without to subscribe to BeginningEdit and CellEditEnding)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看来您也可以从项目视图中获取此信息,即这有效:
我尚未确认这一点,但如果您的绑定集合提供 IEditableCollectionView,您很可能可以在视图模型中获得这些标志。
It seems you can also get this information from the items view, namely this works:
I have not confirmed this but most likely you could get these flags in a viewmodel if your bound collection provides an IEditableCollectionView.
好吧,我还没有找到一个简单的解决方案,也没有人给我指出一个。以下代码可用于将附加属性 IsInEditMode 添加到 DataGrid。希望它对某人有帮助:
要使用它,请将数据网格上的 ProcessIsInEditMode- 属性设置为 true:
之后您将使 IsInEditMode- 属性与 DataGrid 的模式同步。
如果您还需要编辑单元,请相应地更改
BeginningEdit
中的代码。Ok, I havent found a simple solution and no one pointed me to one. The following code can be used to add an attached property IsInEditMode to a DataGrid. Hope it helps someone:
To use it, set on the datagrid the ProcessIsInEditMode- property to true:
Afer that you will have the IsInEditMode-property in sync with the mode of the DataGrid.
If you want also the editing cell, change the code in
BeginningEdit
accoringly.我找到了一个更短的解决方法(VB.NET/C#):VB.NET
C
#:
I found a shorter workaround (VB.NET/C#):
VB.NET
C#:
上面使用 datagridrow 上的 IsEditing 或 IEditableCollectionView 上的 IsEdititngItem 的所有答案对我来说都是部分答案:
如果用户输入版本,然后在任何其他单元格上单击,则会触发 EndEdit 事件,但 DataGridRow 的 IsEditing 属性仍然为 True ! !如果您尝试找到负责的 DataGridCell,其 IsEditingProperty 始终为 false...
我认为这是一个错误。为了获得所需的行为,我必须编写这个丑陋的解决方法
,这基本上会强制网格在任何单元格停止编辑时在 datagridrow 上设置 IsEditing = false 。
All the answers above using IsEditing on the datagridrow or IsEdititngItem on the IEditableCollectionView are partial answers to me :
If the user enter edition, then clics on any other cell, the EndEdit event is fired but the DataGridRow has still the property IsEditing to True !!! And if you try to find the DataGridCell responsible, its IsEditingProperty Is always false...
I think it's a bug. And to have the desired behaviour, I had to write this Ugly workaround
This basicly force the grid to set IsEditing = false on the datagridrow, when any cell stops editing.