Grouping my custom control properties separately in designer grid
Asked Answered
K

1

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

Kling answered 12/7, 2011 at 13:23 Comment(0)
D
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

Downcome answered 12/7, 2011 at 14:48 Comment(7)
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.Kling
Not even in Categorized mode (on propertygrid)?Downcome
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?Downcome
Dear Kornelije Petak, I Have tried it again but still having the same issue i displays MyProperty but not in MyOwn or anyother group.Kling
@Kling are you trying to create a winforms control or some other type?Downcome
@Kling 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.Downcome
Thanks Kornelije Petak, Now it is working after clicking on Categorized.Kling

© 2022 - 2024 — McMap. All rights reserved.