I ran into this issue when I tried to populate a DataGridView with a generic list of my interfaces.
I have two interfaces and to concrete implementations of them:
public interface IMyBaseClass
{
string Name
{
get;
set;
}
}
public abstract class MyBaseClass : IMyBaseClass
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
}
public interface IMyConcreteClass : IMyBaseClass
{
string Description
{
get;
set;
}
}
public class MyConcreteClass : MyBaseClass, IMyConcreteClass
{
private string _description;
public string Description
{
get { return _description; }
set { _description = value; }
}
}
If I bind my grid with a List of IMyConcreteClass, the grid just loads the concrete interface members (Description) but it doesn't loads the base interface members (Name). Here is an example of what i'm doing:
private void Form1_Load(object sender, EventArgs e)
{
//load some data ont mylist
MyConcreteClass classOne = new MyConcreteClass();
MyConcreteClass classTwo = new MyConcreteClass();
classOne.Name = "class one";
classOne.Description = "the class one";
classTwo.Name = "class two";
classTwo.Description = "the class two";
List myList = new List();
myList.Add(classOne);
myList.Add(classTwo);
//add respective columns
DataGridViewTextBoxColumn column1 = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn column2 = new DataGridViewTextBoxColumn();
column1.DataPropertyName = "Name";
column1.Name = "The name";
column2.DataPropertyName = "Description";
column2.Name = "The description";
someGrid.Columns.Add(column1);
someGrid.Columns.Add(column2);
//bind
BindingSource bs = new BindingSource();
someGrid.AutoGenerateColumns = false;
someGrid.DataSource = bs;
bs.DataSource = myList;
}
At the end i just got this on the screen:
Some one knows why is this happening?
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.