consider the following structure
class A {}
class B : A {}
class C : A {}
class D : A {}
...
// in data source class
BindingList<B> d1;
BindingList<C> d2;
BindingList<D> d3;
...
// in datagridview class
void BindDataSource(BindingList<A> source);
void QueryDataSource() {
BindingList<A> source = (BindingList<A>)dgv.DataSource;
A a = source.First(...);
}
I'd like to bind d1
and d2
... to a DataGridView
through BindDataSource
sot that any change to d1
and d2
will automatically be reflected in DataGridView
. From this post I learned that the above code is not valid. But none of the solutions in that post apply to my situation. I tried to change BindDataSource
to the following
void BindingDataSource<T>(BindingList<T> source) where T:A;
but now QueryDataSource
does not compile as I cannot cast the DataSource. Is there any way to solve the whole thing ?