943,717 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 2045
  • C# RSS
Aug 13th, 2009
0

Property Grid Problem

Expand Post »
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:
C# Syntax (Toggle Plain Text)
  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.

C# Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Rezant is offline Offline
3 posts
since Aug 2009
Aug 14th, 2009
0

Re: Property Grid Problem

I changed your code so that you can actually click on the other buttons.
C# Syntax (Toggle Plain Text)
  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
Reputation Points: 69
Solved Threads: 75
Posting Pro in Training
JerryShaw is offline Offline
465 posts
since Nov 2006
Aug 14th, 2009
0

Re: Property Grid Problem

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Rezant is offline Offline
3 posts
since Aug 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Update website control from usercontrol?
Next Thread in C# Forum Timeline: C# Applet?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC