繁体   English   中英

c#winforms属性属性和绑定

[英]c# winforms property attributes and binding

为了向最终用户提供更合适的属性列表,我添加了很多属性属性DisplayNameBrowsable(false)

现在,当试图绑定到原始属性名称时,程序似乎崩溃了(我没有更新所有绑定)。 发生以下错误:

System.ArgumentException: Cannot bind to the property or column MyPropertyName on the DataSource.
Parameter name: dataMember
   at System.Windows.Forms.BindToObject.CheckBinding()
   at System.Windows.Forms.BindToObject.SetBindingManagerBase(BindingManagerBase lManager)
   at System.Windows.Forms.Binding.SetListManager(BindingManagerBase bindingManagerBase)
   at System.Windows.Forms.ListManagerBindingsCollection.AddCore(Binding dataBinding)
   at System.Windows.Forms.BindingsCollection.Add(Binding binding)
   at System.Windows.Forms.BindingContext.UpdateBinding(BindingContext newBindingContext, Binding binding)
   at System.Windows.Forms.Control.UpdateBindings()

这是已知的行为,还是我在寻找错误问题的根源?

感谢Ivan为我指明了正确的方向。

的确Browsable(false)BindingSource删除了该线程中解释的属性。

当我使用DevExpress的属性网格时,使用一个空的DisplayName从其组件中的显示属性列表中将其删除就足够了。因此,我仅添加了EmptyDisplayName属性,该属性返回null作为DisplayName。

请注意,我没有检查这是否适用于其他属性列表。

暂无
暂无

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

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