Datagrid Multiselection of same object

妖精的绣舞 提交于 2019-12-25 01:48:36

问题


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

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.

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.


回答1:


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

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 for the MVVM pattern. With this, you will create such wrapper-objects as part of the design.



来源:https://stackoverflow.com/questions/3667270/datagrid-multiselection-of-same-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!