8

I am working with User Controls. I have created my own control properties. Now I want to group my own properties separately in designer grid.

How to achieve that?

Regards

Kornelije Petak
  • 9,412
  • 15
  • 68
  • 96
Shahzad
  • 81
  • 1
  • 3

1 Answers1

11

Look, here is your answer. In other words, use Category attribute on a property.

Also, here is a link to a useful article (Custom Design-time Control Features in Visual Studio .NET). The article is rather old (2003.), but I couldn't find anything official that is more recent. Also, I don't know if you need any other specific feature, but I guess it should be a good place to start.

I've tried this and it works for me:

public partial class UserControl1 : UserControl
{
    public UserControl1()
    {
        InitializeComponent();
    }

    [Category("MyOwn")]
    public String MyProperty { get; set; }
}

Example1

Note, however, that you can't see your properties when a designer of your user control is open. The custom properties will be visible in designer's property grid only when your user control is a part of another form/control and is selected. While designing your control, you have no designer access to such properties. Look at my picture above. The form contains a user control and then a user control is selected. Then the property is visible on the property grid.

Also, make sure the Categorized is selected in PropertyGrid: Categorized view

Kornelije Petak
  • 9,412
  • 15
  • 68
  • 96
  • Dear, I appreciate your quick response. I have already tried this but of no use. when i add [Category()] with Deafult categories it works fine but when i try to use my own category (like this [Category("Custom")]) it doesn't work. I am using VS2008. – Shahzad Jul 13 '11 at 07:34
  • Not even in Categorized mode (on propertygrid)? – Kornelije Petak Jul 13 '11 at 07:36
  • I've updated my answer. I do use VS2010 so I can't try this on 08, but I don't think there should be any difference. Can you post your code for the desired property? Also, what types are your properties? – Kornelije Petak Jul 13 '11 at 07:42
  • Dear Kornelije Petak, I Have tried it again but still having the same issue i displays MyProperty but not in MyOwn or anyother group. – Shahzad Jul 13 '11 at 08:56
  • @Shahzad are you trying to create a winforms control or some other type? – Kornelije Petak Jul 13 '11 at 09:04
  • @Shahzad try to answer the questions asked in my comments. It's hard to help you if you don't explain what you've tried. Also, I have updated the answer to better explain how this works. – Kornelije Petak Jul 13 '11 at 09:13
  • Thanks Kornelije Petak, Now it is working after clicking on Categorized. – Shahzad Jul 13 '11 at 09:34