Property Grid Problem

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2009
Posts: 3
Reputation: Rezant is an unknown quantity at this point 
Solved Threads: 0
Rezant Rezant is offline Offline
Newbie Poster

Property Grid Problem

 
0
  #1
Aug 13th, 2009
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:
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. Button homebtn = new Button();
  4. homebtn.Text = "New Button";
  5. homebtn.Location = new Point(20, 20);
  6. homebtn.Size = new System.Drawing.Size(75, 23);
  7. homebtn.Name = "Control" + Convert.ToString(controlnum);
  8. controlnum= controlnum+1;
  9. this.panel1.Controls.Add(homebtn);
  10. homebtn.Click += new System.EventHandler(this.SelectEditableControl);
  11. homebtn.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MoveControl);
  12. homebtn.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ControlMouseDown);
  13.  
  14. }

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.

  1. public void SelectEditableControl(object sender, EventArgs e)
  2. {
  3. propertyGrid1.SelectedObject = sender;
  4. propertyGrid1.Refresh();
  5. }

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.
Last edited by Rezant; Aug 13th, 2009 at 11:25 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Property Grid Problem

 
0
  #2
Aug 14th, 2009
I changed your code so that you can actually click on the other buttons.
  1. public partial class Form1 : Form
  2. {
  3. private int controlnum = 0;
  4. public Form1()
  5. {
  6. InitializeComponent();
  7. }
  8. private void button1_Click(object sender, EventArgs e)
  9. {
  10. Button homebtn = new Button();
  11. this.panel1.Controls.Add(homebtn);
  12. homebtn.Text = "New Button" + controlnum.ToString();
  13. homebtn.Location = new Point( 20, controlnum * 23);
  14. homebtn.Size = new System.Drawing.Size(175, 23);
  15. homebtn.Name = "Control" + controlnum.ToString();
  16. controlnum = controlnum + 1;
  17. homebtn.Click += new System.EventHandler(this.SelectEditableControl);
  18. }
  19. public void SelectEditableControl(object sender, EventArgs e)
  20. {
  21. propertyGrid1.SelectedObject = sender;
  22. propertyGrid1.Refresh();
  23. }
  24. }

// Jerry
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 3
Reputation: Rezant is an unknown quantity at this point 
Solved Threads: 0
Rezant Rezant is offline Offline
Newbie Poster

Re: Property Grid Problem

 
0
  #3
Aug 14th, 2009
that wasn't a problem in my project seeing as all the controls are movable, but that could be a problem for others. =) The problem actually was with the custom control I was using. The dll I downloaded from Codeproject was apparently broken, but a fix was available
Last edited by Rezant; Aug 14th, 2009 at 12:47 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC