About the PropertyGird.PropertyValueChanged event

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Danny (anonymous_at_discussions.microsoft.com)
Date: 04/23/04


Date: Thu, 22 Apr 2004 20:06:03 -0700

I put a PropertyGrid in my windows application. I want to change a object's property in Runtime.
I used PropertyValueChanged event to tell the application which property has been changed.
But if the changed property is a collection type object, the event can not occur.
I think it is because that the collection object's instance doesn't have any change, it hasn't been removed or anything.
Only the item's contents have been changed.
So, how could I know this change?
This is my sample:
public class Form1 : System.Windows.Forms.Form
{
     private System.Windows.Forms.ListBox listBox1;
     private System.Windows.Forms.PropertyGrid propertyGrid;
     public Form1()
    {
       InitializeComponent();
    }
    private void InitializeComponent()
    {
       this.propertyGrid = new System.Windows.Forms.PropertyGrid();
       this.listBox1 = new System.Windows.Forms.ListBox();

       this.propertyGrid.Location = new System.Drawing.Point(92, 4);
       this.propertyGrid.Name = "propertyGrid";
       this.propertyGrid.SelectedObject = this.listBox1;
       this.propertyGrid.Size = new System.Drawing.Size(156, 388);
       this.propertyGrid.PropertyValueChanged += new System.Windows.Forms.PropertyValueChangedEventHandler(this.propertyGrid_PropertyValueChanged);

       this.listBox1.Location = new System.Drawing.Point(4, 4);
       this.listBox1.Name = "listBox1";
       this.listBox1.Size = new System.Drawing.Size(88, 43);

       this.Controls.Add(this.listBox1);
       this.Controls.Add(this.propertyGrid);
     }
     private void propertyGrid_PropertyValueChanged(object s, System.Windows.Forms.PropertyValueChangedEventArgs e)
     {
       MessageBox.Show(e.ChangedItem.Label);
     }
}