1

在我加载一个位置的客户列表后,我想选择一个特定的客户作为当前项目。当我尝试移动到当前项目时,没有选择任何项目。我已经(通过调试)验证了我想要移动到的项目存在。

如果我移动到当前项目

(CustomerList.MoveCurrentTo(CustomerList.CurrentItem) //it works but is senseless.
CustomerList is an ICollectionView.

我的问题是“如何将当前项目焦点移动到我选择的特定项目?”。

CustomerList = new CollectionView ( _service.GetCustomers().Where(l => l.LocationID == customer.LocationID));
var item = CustomerList.Cast<AlarmPermit.Entities.Customer>().Where(l => l.BRKey == 52151).Single();
CustomerList.MoveCurrentTo(item);
4

1 回答 1

1

问题似乎是我使用了 CollectionView 而不是从该类派生的类。(谢谢@R.Richards)。MSDN 文档表明 CollectionView 不应直接使用。

在我将集合从 CollectionView 更改为 ListCollectionView 后,代码起作用了。CustomerList 仍然是一个 ICollectionView,但我将 ListCollectionView 对象分配给它。

这是修改后的代码:

CustomerList = new ListCollectionView ( _service.GetCustomers().Where(l => l.LocationID == customer.LocationID).ToList());
var item = CustomerList.Cast<AlarmPermit.Entities.Customer>().Where(l => l.BRKey == 52151).Single();
CustomerList.MoveCurrentTo(item);
于 2017-02-03T21:36:06.047 回答