【发布时间】:2013-11-04 17:46:31
【问题描述】:
这可能是一个非常简单的问题,但我无法弄清楚。我在表单的构造函数中有这么一小行代码:
public FrmMain()
{
InitializeComponent();
gdcSVN.DataSource = _presenter.GetAllFiles();
}
public List<IVersionedFile> GetAllFiles()
{
List<IVersionedFile> all = new List<IVersionedFile>();
all.AddRange(_addedFiles);
all.AddRange(_removedFiles);
all.AddRange(_updatedFiles);
return all;
}
gdcSVN 是一个 DevExpress GridControl。 GetAllFiles 返回一个List<IVersionedFile>,其定义如下:
public interface IUserFile
{
string Name { get; }
string Path { get; }
}
public interface IVersionedFile : IUserFile
{
long Revision { get; }
SvnStatus Status { get; }
}
class VersionedFile : IVersionedFile
{
#region constructors
protected VersionedFile(string name, string path, long revision, SvnStatus status)
{
Name = name;
Path = path;
Revision = revision;
Status = status;
}
public VersionedFile(string name)
: this(name, String.Empty, -1, SvnStatus.Zero)
{}
public VersionedFile(string name, string path)
: this(name, path, -1, SvnStatus.Zero)
{}
public VersionedFile(string name, string path, long revision)
: this(name, path, revision, SvnStatus.Zero)
{}
#endregion
#region IVersionedFile members
public string Name { get; set; }
public string Path { get; set; }
public long Revision { get; set; }
public SvnStatus Status { get; set; }
#endregion
}
当我运行表单时,我的 GridControl 中只有 2 列——Revision 和 Status。如何让网格显示从 IUserFile 接口继承的属性?
编辑澄清;我希望我的网格显示我的 2 个接口之间的所有 4 个属性。 Name、Path、Revision 和 Status。目前,它只显示来自IVersionedFile 的最后两个。
【问题讨论】:
-
我不确定,但我认为您应该通过类中的公共属性获取器公开继承的属性。例如,如果您有一个字符串类型和名称 FirstName 的继承属性,您应该添加 public string FirstName{get{return this.FirstName;}}
-
@Christos 我不确定你的意思。这不是我在我的 IVersionedFile 成员区域内的第二个代码“段落”的最底部所做的吗?
-
@sab669 实际问题是什么?您想在网格中显示哪些字段/属性?
-
@KingKing 我需要能够看到
Name、Path、Status和Revision。在IUserFile中定义。我只得到Revision和Status中定义的IVersionedFile,即使它实现了IUserFile。 -
@sab669 Name 和 Path 是您想要公开的继承属性吗?
标签: c# winforms interface .net-3.5