gpt4 book ai didi

c# - WinForms 数据绑定(bind)到自定义属性引发异常

转载 作者:太空宇宙 更新时间:2023-11-03 13:15:45 24 4
gpt4 key购买 nike

很抱歉,如果这是重复的,但我在网上搜索并没有找到答案

我正在尝试绑定(bind)控件的 Enabled(或 TextBoxReadOnly):

this.tbProj.DataBindings.Add(new Binding("Enabled", this, "CanEdit", false, DataSourceUpdateMode.OnPropertyChanged, false));
this.btnSave.DataBindings.Add(new Binding("Enabled", this, "Dirty", false, DataSourceUpdateMode.OnPropertyChanged, false));

到以下属性:

public bool Dirty { get; set; }

private bool CanEdit
{
get { return this._CurrentRecord.CanEdit(); }
}

我得到 System.ArgumentException: Cannot bind to the property or column CanEdit on the DataSource. 在尝试 ShowDialog() 表单时。

如果我将 EnabledReadOnly 绑定(bind)到 Dirty,一切都很好。我试过 get { return true; } 甚至添加了一个 setter:set { bool bummy=value; },同样的错误。我什至将 CanEdit 更改为自动实现的属性,与 Dirty 相同(只是 get; set; 在声明中)无济于事......

请帮忙。

感谢您的任何提示和建议。

最佳答案

属性必须是公开的:

public bool CanEdit
{
get { return this._CurrentRecord.CanEdit(); }
}

关于c# - WinForms 数据绑定(bind)到自定义属性引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26306642/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com