Beispiel #1
0
    public static void Register(Type type, params PropertyDescriptor[] customProperties)
    {
        var baseProvider   = TypeDescriptor.GetProvider(type);
        var typeDescriptor = new CustomPropertyTypeDescriptor(baseProvider.GetTypeDescriptor(type), customProperties);

        TypeDescriptor.AddProvider(new Provider(baseProvider, typeDescriptor), type);
    }
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        CustomPropertyTypeDescriptor.Register(typeof(OrderLine),
                                              CalculatedProperty.Create("Total", (OrderLine source) => source.Quantity * source.Price)
                                              );

        var form = new Form();
        var dg   = new DataGridView {
            Dock = DockStyle.Fill, Parent = form
        };

        dg.DataSource = Enumerable.Range(1, 10).Select(n => new OrderLine
        {
            ItemNo   = "Item#" + n,
            Quantity = n,
            Price    = 10 * n
        }).ToList();

        Application.Run(form);
    }
Beispiel #3
0
 public Provider(TypeDescriptionProvider baseProvider, CustomPropertyTypeDescriptor typeDescriptor)
     : base(baseProvider)
 {
     this.typeDescriptor = typeDescriptor;
 }