PropertyGrid sees no change of object



  • There's a small editor of the objects of the collection of elements invested in each other. When the first level element is created, it works. PropertyGrid1_PropertyValueChanged As must be done, but when the object is altered to the greater depth of the input, no event arises.

    введите сюда описание изображения

    I tried to build an up-to-date transfer of events that the element had changed, but something got confused about how it works. Probably trying to create a bicycle and solve the problem differently.

    <DataContract()> _
    <Serializable()> _
    Public Class Element
    

    ' Внешнее событие изменения
    Public Event ChangedChildren(ByVal sender As Object)

    ' Внешнее событие изменения
    Public Event ChangedName(ByVal sender As Object)

    ' Fields
    <DataMember()> _
    Private _childs As List(Of Element) = New List(Of Element)

    <DataMember()> _
    Private _atributes As List(Of ElementAttribute) = New List(Of ElementAttribute)

    ' Properties
    Public Property Children() As List(Of Element)
    Set(ByVal value As List(Of Element))
    _childs = value
    RaiseEvent ChangedChildren(Me)
    End Set
    Get
    Return Me._childs
    End Get
    End Property

    Public ReadOnly Property Atributes() As List(Of ElementAttribute)
    Get
    Return Me._atributes
    End Get
    End Property

    Private _name As String

    Public Property Name() As String
    Get
    Return Me._name
    End Get
    Set(ByVal value As String)
    Me._name = value
    RaiseEvent ChangedName(Me)
    End Set
    End Property

    Private _closed As Boolean = True

    Public Property Closed() As Boolean
    Get
    Return _closed
    End Get
    Set(ByVal value As Boolean)
    _closed = value
    End Set
    End Property

    End Class

    UPDATE

    Maybe someone can tell us how to raise the event and use this class's client code as an event?



  • using System;
    using System.ComponentModel.Design;
    using System.Windows.Forms;
    
    public class MyCollectionEditor : CollectionEditor
    {
    public delegate void MyFormClosedEventHandler(object sender,
                                        FormClosedEventArgs e);
    
    public static event MyFormClosedEventHandler MyFormClosed;
    
    public MyCollectionEditor(Type type) : base(type) { }
    protected override CollectionForm CreateCollectionForm()
    {
        CollectionForm collectionForm = base.CreateCollectionForm();
        collectionForm.FormClosed += new FormClosedEventHandler(collection_FormClosed);
        return collectionForm;
    }
    
    void collection_FormClosed(object sender, FormClosedEventArgs e)
    {
        if (MyFormClosed != null)
        {
            MyFormClosed(this, e);
        }
    }
    }
    
    [Editor(typeof(MyCollectionEditor), typeof(UITypeEditor))]
    
    
    public MyForm()
    {
        InitializeComponent();
    
        //  Make the property grid listen to collection properties changes
        MyCollectionEditor.MyFormClosed += new MyCollectionEditor.MyFormClosedEventHandler
                                            (propertyGrid_CollectionFormClosed);
    }
    
    private void propertyGrid_CollectionFormClosed(object s, FormClosedEventArgs e)
    {
        //  Code to run when collection form is closed
    }
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2