问题描述
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.
推荐答案
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中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!