views:

94

answers:

2

Situation I have 3 Interface defined as follows.

public interface IA { long ID { get; set; } }

public interface IB : IA { string Name { get; set; } }

public interface IC : IB { string City { get; set; } }

Then I have a class called SampleClass that implements IC and in that class, I have a method called GetData() which returns List<IC>.

Then in my Windows Form, I have a DataGridView. I am binding the grid as follows.

SampleClass sampleClass = new SampleClass();
List<IC> list = new List<IC>();

foreach (var item in sampleClass.GetData())
{
    list.Add(((C)item));   
}

dataGridView1.DataSource = list;

Question The Grid displays only the fields from Interface IC and none of the fields from interface IB or IA shows up. Any idea why?

A: 

The datasource is binded to a list of IC, the grid display IC data. If you bind your grid the the concrete class that inherit IC, you will be able to see IB too.

Daok
A: 

You need to provide a List < SampleClass > instead.

eschneider