I've been working on a project for a few days now and have hit a part of the project that I don't know how to fix. I have a propertygrid control on the form and buttons that create controls when pressed.
Here's how I am creating the controls:
private void button1_Click(object sender, EventArgs e)
{
Button homebtn = new Button();
homebtn.Text = "New Button";
homebtn.Location = new Point(20, 20);
homebtn.Size = new System.Drawing.Size(75, 23);
homebtn.Name = "Control" + Convert.ToString(controlnum);
controlnum= controlnum+1;
this.panel1.Controls.Add(homebtn);
homebtn.Click += new System.EventHandler(this.SelectEditableControl);
homebtn.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MoveControl);
homebtn.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
}
Then when the user clicks on the control it brings up a list of properties in the property grid using the method SelectEditableControl. All created controls use this method.
public void SelectEditableControl(object sender, EventArgs e)
{
propertyGrid1.SelectedObject = sender;
propertyGrid1.Refresh();
}
The problem is when you have created multiple controls . It won't change objects it just stays on the current object. I was thinking about setting the propertygrid's selectedobject to null but this didn't work. Thanks in advance for any help.