WinForms databind to collection property (such as count)

Posted by Ornus on Stack Overflow See other posts from Stack Overflow or by Ornus
Published on 2010-01-26T19:40:53Z Indexed on 2010/03/28 13:03 UTC
Read the original article Hit count: 458

Filed under:
|
|

I want to databind to a collection property, such as Count.

in general, when I data bind I specify data member for the object property in the collection, not for the actual properties collection itself exposes.

for example, I have a list of custom objects. I show them in datagridview. but I also want to show their total count using a separate label. is there a way to do this through databinding?

I imagine that somehow I need to force PropertyManager to be used, instead of CurrentyManager?

I get the following exception. Notice that DataSource is collection and has TotalValue property.

System.ArgumentException: Cannot bind to the property or column TotalValue on the DataSource.
Parameter name: dataMember
   at System.Windows.Forms.BindToObject.CheckBinding()
   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.Binding.SetBindableComponent(IBindableComponent value)
   at System.Windows.Forms.ControlBindingsCollection.AddCore(Binding dataBinding)
   at System.Windows.Forms.BindingsCollection.Add(Binding binding)

© Stack Overflow or respective owner

Related posts about .NET

Related posts about winforms