如何删除列表视图行而不影响其项目源 [英] how to make a listview row removed without affecting its item source

查看:87
本文介绍了如何删除列表视图行而不影响其项目源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我有一个listview,iam将数据表绑定为itemsource。我在列表视图的每一行都有RemoveButton。当我点击它时我想从listview中删除该listitem而不从datatable中删除该行。有人请帮帮我。



谢谢

hi I have a listview to which iam binding a datatable as itemsource.I have RemoveButton in Each row of list view.when i click it i want to remove that listitem from listview without removing that row from datatable..Anybody please help me with this.

Thanks

推荐答案

如果将数据源绑定到列表在WPF中控制,如果数据源是一个ObservableCollection,控件的任何删除都会传播到数据源。

因此,实现方案的唯一方法是在每次删除时手动重新填充List 。但是,如果您再次尝试删除,则需要将当前列表保存在某处,以便确定哪条记录被删除。



最好的办法是绑定配置为单向绑定而不是双向绑定。然后List将使用数据源绑定一次,任何修改都不会被发送回支持字段。
If you bind a datasource to a list control in WPF, if the datasource is an ObservableCollection, any deletion from the control will get propagated to the datasource.
So the only way you scenario can be implemented is to have the List repopulated manually upon each deletion. However if you try to delete again, you will need to have the current list saved somewhere so that you are sure which record gets deleted.

Best way is to have the binding configured as 1-way binding instead of 2-way. Then the List will get binded once using the datasource and the any modification will not be sent back to the backing field.


这篇关于如何删除列表视图行而不影响其项目源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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