I am trying to bind some controls to an object - which is normally a pretty straightforward process. Unfortunately, if the object that I'm binding to inherits from CollectionBase, binding to that classes fields causes the error:
Cannot bind to the property or column Caption on the DataSource. Parameter name: dataMember
Removing the collectionbase inheiritance makes this issue go away, but I need this object to be a collection. It seems as though CollectionBase causes higher level properties to become "unbindable." Is there some property I can override to fix this? Any other ideas?
I found this example online that summarized the issue pretty easily. Unfortunately, I have yet to find an answer in all the places I've seen this example posted.
Code:
[STAThread]
static void Main()
{
TestCollection obj = new TestCollection();
using (Form f = new Form())
using (BindingSource bs = new BindingSource())
{
bs.DataSource = typeof(Test);
f.DataBindings.Add("Text", bs, "Caption");
bs.DataSource = obj; // breaks
//List<TestallData = new List<Test>();
//allData.Add(obj);
//bs.DataSource = allData;
f.ShowDialog();
}
}
class TestCollection : CollectionBase
{
public string Caption { get { return "Working"; } }
}