简体   繁体   English

Wpf 排序或数据网格上的 crud 导致重置复选框

[英]Wpf sort or crud on datagrid cause reset checkbox

I added column that has checkbox and when checkbox checked i get average of some numbers that selected.我添加了具有复选框的列,当复选框被选中时,我得到了一些选定数字的平均值。

The problem is when sorting data or do something to database cause all checkbox check status to false.问题是在对数据进行排序或对数据库执行某些操作时会导致所有复选框检查状态为 false。 How to fix it?如何解决?

The only way i know is store that checkbox as boolean in database and everytime i run the program set all boolean to false.我知道的唯一方法是将该复选框存储为数据库中的 boolean 并且每次我运行程序时将所有 boolean 设置为 false。 But that is not good way.但这不是好办法。 Because in large data cause slowly down the performance of program.因为在大数据中导致程序性能缓慢下降。

(i don't know my grammer is right, so hope you understand what my problem is) (我不知道我的语法是对的,所以希望你明白我的问题是什么)

Make sure you are using a ObservableCollection and once necessary action complete, SaveChages to the database.确保您使用的是 ObservableCollection,一旦必要的操作完成,将 SaveChages 保存到数据库。 Then do your refresh or reload whatever.然后进行刷新或重新加载任何内容。 It seems, you are reloading the data, which is not necessary as long as the context is alive.看来,您正在重新加载数据,只要上下文处于活动状态,就没有必要这样做。 Just make sure you are saving the new state of the collection to you DB (use that same context you used to load the data) I hope it helps只需确保将集合的新 state 保存到数据库(使用与加载数据相同的上下文)我希望它有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM