Datagrid同一对象的多重选择 [英] Datagrid Multiselection of same object

查看:138
本文介绍了Datagrid同一对象的多重选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

wpf datagrid将绑定到可观察的员工详细信息集合。

wpf datagrid in which will bind to an observable collection of employee details.

从用户选择员工时,网格将从另一个屏幕加载。如果用户选择员工A多次相同的记录将加载到这个网格。

Grid will loaded from another screen upon selection of employees by user.If user selecting employee A multiple times same record will loaded in to this grid.

但是我的问题是当我选择员工A,然后选择另一行的同一个员工A我的行选择样式是适用于两个记录。我将网格的选择模式属性设置为单个。

But my problem is when i select employee A and then selecting the same employee A of another row my row selection style is applicable to both records. I set selection mode property of grid to Single.

然后也会有相同的多个选择相同的记录。

then also same multiple selection of same record is happening.

请您帮助我解决这个特殊问题。

Could any one of you please help me out to solve this peculiar issue.

推荐答案

问题是因为DataGrid使用 Equals()进行选择。对于同一个雇员,equals等于true。

The issue comes because DataGrid uses Equals() to do the selection. And equals returns true for the same employee.

一种可能性是使用包装您的员工并提供其数据的包装对象a。那么问题将被解决,因为Equals只返回true,如果引用是相等的(只要你不重写它)。

A possibility is to use wrapper-object a that wraps the your Employee and provides its data. Then the problem will be resolved because the Equals returns only true if the reference is equal (as long as you don't override it).

Google为MVVM模式。有了这个,你将创建这样的包装对象作为设计的一部分。

Google for the MVVM pattern. With this, you will create such wrapper-objects as part of the design.

这篇关于Datagrid同一对象的多重选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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