OnTheFly
OnTheFly

Reputation: 2101

How to use BindingList of object of different classes sharing same interface as datasource of datagridview

I have many classes sharing a interface.I have also created a BindingList consist of objects created from these classes.

Now i want to use this binding list as a Datasource for a Datagridview.

would this work?can please someone give me some example.

Upvotes: 1

Views: 1364

Answers (1)

RQDQ
RQDQ

Reputation: 15569

Oh wait - can you just create a BindingList of IMyInterface ?

myList = new List<IMyInterface>();

myList.Add(new Foo());
myList.Add(new Bar());

myDataGridView.DataSource = myList;

Foo and Bar implement IMyInterface

Upvotes: 2

Related Questions