title: How to connect a custom propertyGrid with a standard control in C#?
body: <p>I am creating a graphing program and I would like to allow the user to be able to change the look of the graph they create. Providing them with the opportunity to change the series color, data point size, ect. I am allowing them to do this through the use of a propertyGrid. Through the help of the wonderful people who use stack overflow I was able to import all the properties of a chart into my property grid, however; Now I can't figure out how to connect my chart to the propertyGrid, so when I change something in the grid the chart changes. </p>
  
  <p>So far I have </p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
          magRadioBox.Checked = true;
          PropertyGrid propertyGrid1 = new PropertyGrid();
          propertyGrid1.CommandsVisibleIfAvailable = true;
          propertyGrid1.Text = "Graph and Plotting Options";
          propertyGrid1.PropertyValueChanged += propertyGrid1_PropertyValueChanged;
  
          this.Controls.Add(propertyGrid1);
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
          this.Text = "MY Plot Program";
          propertyGrid1.SelectedObject = chart1; 
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          //some code that is populating my chart(chart1) with data 
          //....chart1 being filled with data 
      }
  
      private void propertyGrid1_PropertyValueChanged(object s , PropertyValueChangedEventArgs e)
      {
          //Getting the MyChart instance from propertyGrid 
          MyChart myChart = (MyChart)(((PropertyGrid)s.SelectedObject);
          //Calling the method that will refresh my chart1 
          myChart.Invalidate(); 
      }
  </code></pre>
  
  <p>The above code is for my Form. The my "MyChart" class code is</p>
  
  <pre><code>namespace FFT_Plotter
  { 
      [DefaultPropertyAttribute("Text")]
      public class MyChart : Chart 
      {
          public event EventHandler PropertyChanged;
  
          private void OnPropertyChanged(object sender, EventArgs e)
          {
              EventHandler eh = propertyChanged;
              if(eh !=null)
              {
                  eh(sender, e);
              }
  
              [BrowsableAttribute(false)]
              public new System.Drawing.Color BackColor
              {
                  get { return BackColor; }//Here back color is just an example of a property, not necessarily one that I would make non-Browsable
                  set 
                  { 
                      base.BackColor = value; 
                      OnPropertyChanged(this,EventArgs.Empty);
                  }
              }
          }
      }
  </code></pre>
  
  <p>The class above gets me so far as having a property grid that has all the properties of a chart and allows me to hide those properties as I see fit. However now I am stuck in understanding how to connect my chart1 to the grid I've created. If anyone has any advice on how to do that, it would be incredibly helpful. </p>