当数据从wpf中的数据库绑定到listview时,如何检查listview中的复选框 [英] how to check the checkbox inside listview when data is bind to the listview from database in wpf

查看:63
本文介绍了当数据从wpf中的数据库绑定到listview时,如何检查listview中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


i我在listview中有复选框,我正在从数据库绑定数据到该列表视图。

我现在想要的是数据何时绑定到列表视图我希望复选框被检查

。为此我尝试引用按钮事件中的复选框并选中复选框但是

它将显示错误message null引用异常对象引用未设置为实例

对象



这里是我在按钮点击事件中的代码



hi
i am having checkbox inside listview and i am binding data to that listview from database.
what i want now is when the data is bind to the listview i want the checkbox to be checked
.for that i try to refer the checkbox in the button event and make the checkbox checked but
it will display an error message null reference exception object reference not set to instance
of an object

here is my code in the button click event

CheckBox myTextbox = GetTemplateChild("chb_standard") as CheckBox;
                  
                        myTextbox.IsChecked = true;
                    
if any one have any idea help  me thanks in advance.

推荐答案

将IsChecked属性绑定到公共属性以处理这种情况会更容易。



例如:



Would be easier to bind the IsChecked property to a public property to handle this situation.

For example:

private bool _cbIsChecked;







public bool CbIsChecked
{
     get{return _cbIsChecked;}
     set{_cbIsChecked = value;}
}





然后你应该定义一个设置了这个属性的方法。 br />


不要忘记实现INotifyPropert yChanged,因此用户界面会刷新自己。

在公共财产中提升它。



如果有任何进一步的问题,请问问。



希望有所帮助:)



Then you should define a method where this property is been set.

Don't forget to implement the INotifyPropertyChanged, so the UI refreshes itself.
Raise it in the set of the public property.

For any further questions, just ask.

Hope it helps :)


这篇关于当数据从wpf中的数据库绑定到listview时,如何检查listview中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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