I am trying to bind the grid to a datasource defined as an interface. The interface has one property that is an ienumerable of another interface. When I set the first interface as the datasource for the grid, the designer will not let me set properties for the inner band, as it doesn't show me any of the columns for that band. I have attached a sample project to demonstrate this. Here are some screenshots to illustrate the problem:
1) This shows the grid in the designer with the inner band expanded
2) This shows the columns collection within the grid's custom property editor
And finally, here is the grid at runtime, populated with sample data. The inner band is displaying correctly at run time, but without design time access I can't control its appearance:
Hmm, the problem seems to be with the declaration of the child interface property within the parent interface. Neither of the following work:
Property
If I use the concrete class variant though, and declare it as a List(of ConcreteRate) then it works properly.
How can I get around this?
Hi,
peelports said:How can I get around this?
It seems as though you have already discovered how to get around it. :)
Using an Interface as a type for DataBinding is not a good idea. The BindingManager needs to determine the data structure for the grid. If there are actual rows of data, then it can use these rows to determine the structure, which is probably why it works at run-time.
But at design-time, when there are no rows, it will try to create one. Since it cannot create an instance of an interface, it won't be able to determine the structure.
I strongly recommend not binding to Interface types like IList<T> or IBindingList<T>. You will run into all sorts of problems with this. Use List<T> or BindingList<T> instead. Also note that BindingList<T> is far more robust for binding. List<T> will impose all sorts of limitations - for example, your will not be able to add new rows to the grid.