Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sorry for asking this but I'm finding it very difficult to find an easily understandable article/blog at noob level. C#, VS2010,desktop application.

My user control consists of a panel parenting a datagridview and other child controls.
As a datagridview has hundreds of properties, I wanted to expose it in the property editor at design time and persist it's properties in the simplest way possible.
public DataGridView View
{
  get { return dgv; }
}

The above doesn't expose the datagrid view in the designtime property viewer, but the following code does
C#
[TypeConverter(typeof(ExpandableObjectConverter))]
public DataGridView View
{
  get { return dgv; }
}

But, the above doesn't persist the datagridview properties in my form.designer.cs file.
How do I persist it's properties please?
Posted
Comments
Sergey Alexandrovich Kryukov 20-Oct-11 18:26pm    
Add to tags: C# and UI library. Forms? "Desktop application" is not a certain thing.
--SA

I think I've done it. I'm reporting my solution in case anybody else is struggling

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public DataGridView View
{
get { return dgv; }
}

The above exposes the DataGridView in the property browser, and persists the datagridview in my Form.Designer.cs file. It also handles events :)
 
Share this answer
 
To allow properties modification during design time, you need to expose them in your user control as children remains private. If you need to expose some of the properties of the child control, you will need to do it one by one. Here is the simple example:

C#
MyUserControl : UserControl {
   public string TextBoxText { get { return TextBox.Text; } set { TextBox.Text = value; } }
   public Color TextBoxBackColor { get { return TextBox.BackColor; } set { TextBox.BackColor = value; } }
   public Color TextBoxForeColor { get { return TextBox.ForeColor; } set { TextBox.ForeColor = value; } }
   //...
   private TextBox TextBox = new TextBox();
   //...
}


Everything will persist properly without any effort from you, just don't use TypeConverter.

—SA
 
Share this answer
 
Comments
czeshirecat2 21-Oct-11 4:19am    
Thank you for trying to help :)
I've written some user controls in the past, and with those I've passed properties through to the child control.
It's not what I want to do in this case.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900