0

In order to get a more presentable list of properties to the end-user, I've added quite a lot of property attributes DisplayName and Browsable(false).

Now, it appears the program crashes when trying to bind to the original property name (I didn't update all bindings). Follwoing error occurs:

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

Is this a known behaviour, or am I looking at the wrong problem's origin?

neggenbe
  • 1,697
  • 2
  • 24
  • 62
  • 1
    Make sure you have a property with name (not display name) `MyPropertyName` and it is not marked with `Browsable(false)`. – Ivan Stoev Jan 31 '17 at 18:03
  • yep well, that's exactly the problem... It is marked as `Browsable(false)` because I don't want to see it in the property list... So no way around this, as far as I can tell?? – neggenbe Jan 31 '17 at 18:09
  • No if you want to use it for data binding. `Browsable(false)` is removing it from the properties eligible for data binding. – Ivan Stoev Jan 31 '17 at 18:13
  • Not sure what are you trying to achieve. Are you seeking for [`EditorBrowsableAttribute`](https://msdn.microsoft.com/en-us/library/system.componentmodel.editorbrowsableattribute(v=vs.110).aspx)? – Ivan Stoev Jan 31 '17 at 18:16
  • @IvanStoev unfortunately this doesn't work... – neggenbe Jan 31 '17 at 18:25

1 Answers1

0

Thanks to Ivan pointing me to the right direction.

Indeed Browsable(false) removes the property from BindingSource as explained in this thread.

As I use DevExpress' property grid, it is sufficient to use an empty DisplayName to remove it from the list of showing properties in their components... So I simply added a EmptyDisplayName attribute which returns null as the DisplayName.

Note that I didn't check if this works for other property lists.

Community
  • 1
  • 1
neggenbe
  • 1,697
  • 2
  • 24
  • 62