DataGrid SelectionUnit = Cell禁用对选定行的所有支持? [英] DataGrid SelectionUnit=Cell disables all support for a selected row?

查看:61
本文介绍了DataGrid SelectionUnit = Cell禁用对选定行的所有支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.Net 4 WPF DataGrid C#MMVM

.Net 4 WPF DataGrid C# MMVM

当DataGrid SelectionUnit为全行时,wpf数据绑定和collectionview负责让我知道在viewmodel中是什么通过视图的currentitem属性有效选择的项目。这对于将选择模式设置为全行的只读网格非常有用。

When the DataGrid SelectionUnit is full row, wpf databinding and the collectionview take care of letting me know in the viewmodel what is the actively selected item via the view's currentitem property. This works great for readonly grids with the selection mode set to the fullrow.

现在我有一个可编辑的网格。因此,我将SelectionUnit = Cell设置为使查找一个单元格更容易。现在,网格突然变得不再具有跟踪选择项的能力。设置为单元格模式时,我什至无法设置SelectedItem。因此,现在视图模型始终认为它在第一行。我可以处理网格中的SelectedCellsChanged来确定我所在的行,但由于无法再设置网格的SelectedItem,我无法让viewmodel知道!

Now I have an editable grid. So I set the SelectionUnit=Cell to make it easier to spot which cell one is in. Now all of a sudden the grid no longer has any ability to track the selection item. I can't even set SelectedItem when set to cell mode. So now the viewmodel always thinks it's on the first row. I can handle SelectedCellsChanged in the grid to figure out what row I'm on, I just have no way of letting the viewmodel know since the grid's SelectedItem can no longer be set!

我不明白为什么在单元格选择模式下网格仍然不能具有SelectedItem。

I don't understand why the grid can't still have a SelectedItem when in cell select mode.

对网格进行硬编码以将ItemSource投射到我的网格上collectionview可以从SelectedCellsChanged事件中调用MoveCurrentTo,是否还有其他MVVM真正的方法来使视图的CurrentItem与网格保持同步?

Short of hardcoding into my grid to cast the ItemSource to my collectionview to call MoveCurrentTo from the SelectedCellsChanged event, is there any other MVVM true way to keep the view's CurrentItem in sync with the grid?

要么,要么我更改了网格样式,以在我有可编辑的网格时删除或减少行突出显示效果。

Either that, or I change the grid style to remove or reduce the row highlight effect when I have an editable grid.

推荐答案

我正在寻找相同的问题并发现一个简单的解决方案

I was searching for the same problems and found a simple solution

要访问将 SelectionUnit 设置为 Cell ,您必须这样做:

To access to the row with SelectionUnit set to Cell you have to do:

DataGridXX.SelectedCells[0].item

只有在您可以一次只能选择一个单元格(不在扩展模式下)。

It works only if you can select only one cell at time (not in Extended mode).

这篇关于DataGrid SelectionUnit = Cell禁用对选定行的所有支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆