我有基类和一些继承的类,如下所示:
public abstract class Base
{
public long ID { get; set; }
public string Name { get; set; }
public virtual string Description { get { return "Base"; } }
}
public class A : Base
{
public override string Description { get { return "A"; } }
}
public class B : Base
{
private string extraInfo;
public override string Description { get { return "B"; } }
public string ExtraInfo
{
get { return extraInfo; }
set { extraInfo = value; }
}
}
我收集了这些对象,并将此集合设置为DataSource
的{{1}}。然后,DataGridView
的列将由DataGridView
类的属性(Base
,ID
。Name
)创建。有没有办法反映具体的实施属性?
Description
在这种情况下,我还想要类 List<Base> items = new List<Base>();
DataGridView dgv = new DataGridView();
dgv.DataSource = new BindingList<Base>(items);
的{{1}}属性列。
答案 0 :(得分:0)
继承B类:
public class Base
{
public long ID { get; set; }
public string Name { get; set; }
public virtual string Description { get { return "Base"; } }
}
public class A : Base
{
public override string Description { get { return "A"; } }
}
public class B : Base
{
private string extraInfo;
public override string Description { get { return "B"; } }
public string ExtraInfo
{
get { return extraInfo; }
set { extraInfo = value; }
}
}