相关疑难解决方法(0)

ICustomTypeDescriptor,TypeDescriptionProvider,TypeConverter和UITypeEditor

我试图全面了解如何使用ICustomTypeDescriptor,TypeDescriptionProvider,TypeConverter和UITypeEditor来更改PropertyGrid显示和与对象接口的方式.

有人可以告诉我这是对的,还是我错过了任何重大概念或要点?我真的只是想了解为什么以及何时使用每个班级.

ICustomTypeDescriptor

  • 在类中实现此接口会完全覆盖类的本机属性,并将其替换为ICustomTypeDescriptor.GetProperties()返回的PropertyDescriptors.

TypeDescriptionProvider

  • 用于扩展类的现有属性
  • TypeDescriptionProvider通过TypeDescriptionProvider属性附加到类
  • TypeDescriptionProvider的GetTypeDescriptor()方法返回要附加到该类型的现有属性的ICustomTypeDescriptor .
  • PropertyGrid将显示通过Reflection找到的类的属性,以及通过TypeDescriptionProvider添加到类的属性

类型转换器

  • 在类型之间转换
  • 在使用PropetyGrid方面,用于在可以在属性网格中显示/编辑的复杂类型和基元类型之间进行转换.
  • TypeConverter的GetStandard值方法还可用于显示propertygrid中可能值的列表

UITypeEditor的

  • 定义用于操作复杂类型属性的自定义编辑器.
  • 通过属性与属性相关联.

因此,ICustomTypeDescriptor和TypeDescription提供程序用于添加/更改/替换对象的整个属性.TypeConverter和UITypeEditor应用于各个属性,并控制这些特定属性的接口方式.

c# propertygrid uitypeeditor typeconverter customtypedescriptor

38
推荐指数
1
解决办法
9468
查看次数

数据绑定动态数据

我有一组"动态数据",我需要绑定到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)

c# data-binding winforms

28
推荐指数
1
解决办法
2万
查看次数

绑定IList <IMyInterfaceType>不显示IMyInterface继承的接口成员

我将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

14
推荐指数
1
解决办法
1222
查看次数