Basically, you'd either need to create your own editor, or subclass CollectionEditor
and mess with the form. The latter is easier - but not necessarily pretty...
The following uses the regular collection editor form, but simply scans it for PropertyGrid
controls, enabling HelpVisible
.
class DescriptiveCollectionEditor : CollectionEditor
{
public DescriptiveCollectionEditor(Type type) : base(type) { }
protected override CollectionForm CreateCollectionForm()
{
CollectionForm form = base.CreateCollectionForm();
form.Shown += delegate
{
ShowDescription(form);
};
return form;
}
static void ShowDescription(Control control)
{
PropertyGrid grid = control as PropertyGrid;
if (grid != null) grid.HelpVisible = true;
foreach (Control child in control.Controls)
{
ShowDescription(child);
}
}
}
To show this in use (note the use of EditorAttribute
):
class Foo {
public string Name { get; set; }
public Foo() { Bars = new List<Bar>(); }
[Editor(typeof(DescriptiveCollectionEditor), typeof(UITypeEditor))]
public List<Bar> Bars { get; private set; }
}
class Bar {
[Description("A b c")]
public string Abc { get; set; }
[Description("D e f")]
public string Def{ get; set; }
}
static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.Run(new Form {
Controls = {
new PropertyGrid {
Dock = DockStyle.Fill,
SelectedObject = new Foo()
}
}
});
}
}