views:

2237

answers:

3

Is there a built-in editor for a multi-line string in a PropertyGrid.

+3  A: 

No, you will need to create what's called a modal UI type editor. You'll need to create a class that inherits from UITypeEditor. This is basically a form that gets shown when you click on the ellipsis button on the right side of the property you are editing.

The only drawback I found, was that I needed to decorate the specific string property with a specific attribute. It's been a while since I had to do that. I got this information from a book by Chris Sells called "Windows Forms Programming in C#"

There's a commercial propertygrid called Smart PropertyGrid.NET by VisualHint.

hectorsosajr
A: 

Yes. I don't quite remember how it is called, but look at the Items property editor for something like ComboBox

Edited: As of @fryguybob, ComboBox.Items uses the System.Windows.Forms.Design.ListControlStringCollectionEditor

Ilya Ryzhenkov
ComboBox.Items uses the System.Windows.Forms.Design.ListControlStringCollectionEditor, I don't think that is quite what I'm looking for, but it is close.
fryguybob
+10  A: 

I found that System.Design.dll has System.ComponentModel.Design.MultilineStringEditor which can be used as follows:

public class Stuff
{
    [Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
    public string MultiLineProperty { get; set; }
}
fryguybob
What version of the .NET Framework did you find that in?
hectorsosajr
http://msdn.microsoft.com/en-us/library/system.componentmodel.design.multilinestringeditor.aspxindicates that it is in 2.0, 3.0, and 3.5.
fryguybob
How to use this? I am trying to write [Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))] [CategoryAttribute("Misc"), Description("All http headers for this mail."), DisplayName("HTTP Headers")] public string HttpHeaders { get { return mail.HttpHeaders; } }but this does not display HttpHeaders as multiline.
Alex
It is a multiline *editor* so I think you would only see a difference when editing, so it would only apply to properties with a public setter.
fryguybob
Thanks fryguybob!Do you know a way to SHOW multiline string in a grid? Not to edit?Thanks!
Alex