我试图全面了解如何使用ICustomTypeDescriptor,TypeDescriptionProvider,TypeConverter和UITypeEditor来更改PropertyGrid显示和与对象接口的方式.
有人可以告诉我这是对的,还是我错过了任何重大概念或要点?我真的只是想了解为什么以及何时使用每个班级.
ICustomTypeDescriptor
TypeDescriptionProvider
类型转换器
UITypeEditor的
因此,ICustomTypeDescriptor和TypeDescription提供程序用于添加/更改/替换对象的整个属性.TypeConverter和UITypeEditor应用于各个属性,并控制这些特定属性的接口方式.
c# propertygrid uitypeeditor typeconverter customtypedescriptor
我有一组"动态数据",我需要绑定到GridControl.到目前为止,我一直在使用标准的DataTable类,它是System.Data命名空间的一部分.这工作得很好,但我被告知我不能使用它,因为它对于客户端和服务器之间的网络序列化太重了.
所以我认为我可以通过简单地使用List<Dictionary<string, object>>List表示行集合的类型来轻松复制DataTable类的"简化"版本,并且每个Dictionary表示一行,其中列名称和值为KeyValuePair类型.我可以设置Grid以使列DataField属性与Dictionary中的键匹配(就像我为DataTable的列名所做的那样).
但是做完之后
gridControl.DataSource = table;
gridControl.RefreshDataSource();
Run Code Online (Sandbox Code Playgroud)
网格没有数据......
我想我需要实施IEnumerator- 对此的任何帮助都将不胜感激!
示例调用代码如下所示:
var table = new List<Dictionary<string,object>>();
var row = new Dictionary<string, object>
{
{"Field1", "Data1"},
{"Field2", "Data2"},
{"Field3", "Data3"}
};
table.Add(row);
gridControl1.DataSource = table;
gridControl1.RefreshDataSource();
Run Code Online (Sandbox Code Playgroud) 我将IList绑定到GridView.IMyInterface看起来像
public interface IMyInterface: IHasTotalHours, IHasLines
{
DateTime GoalStartDate { get; set; }
DateTime GoalEndDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我将一个实例绑定到Grid,如下所示:
IList<IMyInterface> instance= GetMyData();
myGrid.DataSource = instance;
myGrid.DataBind();
Run Code Online (Sandbox Code Playgroud)
将此绑定到网格时,显示在网格中的唯一成员是IMyInterface的直接成员:GoalStartDate和GoalEndDate.
这是为什么?如何让网格显示其继承的其他接口的成员?
更新 继承的接口定义简单的数据属性,如
public interface IHasTotalHours
{
string Description { get; set; }
int Hours{ get; set; }
}
public interface IHasLines
{
double TotalLines { get; set; }
double LinesPerHour { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
有一个实现IMyInterface的类:
public class MyClass : IMyInterface
{
public string Description { get; set; }
public …Run Code Online (Sandbox Code Playgroud) data-binding reflection interface multiple-inheritance typedescriptor