Diana
Diana

Reputation: 839

XCeed PropertyGrid: How to set the right title?

I've implemented ICustomTypeDescriptor to provide my custom descriptor to the XCeed Propertygrid.

public class MyDescriptor : ICustomTypeDescriptor, IDisposable
{
    public MyDescriptor(IMyInterface metadata)
    {
         /* Use object metadata to build the type descriptor */
    }
}

This works fine, except that the PropertyGrid has as Title "MyDescriptor". I've tried implementing GetAttributes()

public AttributeCollection GetAttributes()
{
    string theRightTitle = metaData.GetTitle(); // Dynamic title, differs depending on metaData object provided in constructor.
    Attribute[] attributes = new Attribute[] {new DescriptionAttribute(theRightTitle) };
    return new AttributeCollection(attributes);
}

But that doesn't work... How do I ensure that the title of my grid is correct?

Edit: So what I need is a dynamic way of generating the Title for the PropertyGrid. I've updated the code samples above to reflect this.

Upvotes: 1

Views: 1430

Answers (3)

user2981965
user2981965

Reputation: 13

Or you can use combination of static and dynamic info like:-

[DisplayName("Data")]
public class MyDescriptor : ICustomTypeDescriptor
{
    public string Name
    {
      get
      {
        return " - My Title";
      }
    }
    . . .
}

Title of property grid will be "Data - My Title"

Upvotes: 0

Mathieu Drimonakos
Mathieu Drimonakos

Reputation: 26

What you see at the top of the PropertyGrid is not the Title, it’s the TypeName along with an empty title. If you want to see a title beside the TypeName, make sure your class contains a “Name” property. Without the “Name” property, an empty string is added as the title.

public class MyDescriptor : ICustomTypeDescriptor
{
    public string Name
    {
      get
      {
        return "AAA";
      }
    }
    . . .
}

Upvotes: 1

cls71
cls71

Reputation: 177

I have decorated my class with DisplayName attribute and works right.

[DisplayName("My Custom Title")]
public class MyConfiguration
{ ... }

enter image description here

Upvotes: 1

Related Questions