c#winforms属性属性和绑定

时间:2017-01-31 17:59:01

标签: c# .net binding attributes

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

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

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()

这是一种已知的行为,还是我在看错了问题的来源?

1 个答案:

答案 0 :(得分:0)

感谢Ivan指出我正确的方向。

确实Browsable(false)会移除BindingSource中的属性,如this thread中所述。

因为我使用DevExpress'属性网格,使用空的DisplayName将其从组件中的显示属性列表中删除就足够了......所以我只添加了一个EmptyDisplayName属性,它返回null作为DisplayName。

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