I have encountered a strange behavior of BindingSource. First I set it’s DataSource in designer to a type that will be used by UI for binding, but when I then retrieve the data, then I set the DataSource to a Collection of this type. Everything works fine when the Collection actually stores some objects. Problems begin, when it’s empty (not null, just empty). The BindingSource becomes suspended, and even adding something to the Collection doesn’t change it, ResumeBinding has no effect too. In this state it’s completely useless.
I found a workaround which is simply setting the DataSource to null and then to the same Collection, but this time with added elements (without the setting to null it doesn’t work). Can someone explain this to me? Why BindingSource behaves this way? And, of course, is there an elegant way to solve this? I don’t like the solution that I found.
Collection<T>doesn’t support list notifications, so it has no way of telling the UI to update or do anything useful. Changing toBindingList<T>instead ofCollection<T>should solve this.