views:

617

answers:

2

I'm using the PropertyGrid control in a WinForms application. The window itself binds to a class that contains a list of objects. While I'd prefer it if the grid just expanded and let the user modify the items like a tree-view, I'll settle for the collection editor if it will stop listing the members as "Roswell.Windows.Command.Model" (the fully-resolved class name).

I have appplied the DisplayName attribute to both the containing property and the class itself, but the collection editor window itself seems to ignore it.

(FWIW, this is .NET 3.5 in VStudio 2008.)

Any suggestions? I've googled (and SO'd!!) until I'm blue in the face.

+2  A: 

You can override the ToString method to provide a nicer value (C# example)

class MyClass
{
    public string SomeValue { get; set; }

    public override string ToString()
    {
        return string.Format("SomeValue={0}", this.SomeValue);
    }
}
Fredrik Mörk
Great! Any ideas how I get the thing to show up as an expandable list in the grid itself, rather than relying on the collection editor?
Mike Hofer
I don't know from the top of my head to achieve that with an array, but you should research into implementing a TypeConverter (as suggested by leppie) and a UI Type Editor.
Fredrik Mörk
+2  A: 

You can override ToString()

  • or -

Implement a TypeConvertor for your class or property.

leppie
That did the trick. Of course, it was a bit more complicated than I expected, but it certainly worked. I'd vote you up again if I could!!
Mike Hofer