Fondamentalement, vous auriez soit besoin de créer votre propre éditeur, ou sous-classe CollectionEditor
et jouer avec le formulaire. Ce dernier est plus facile - mais pas nécessairement joli ...
Ce qui suit utilise le formulaire éditeur de collection standard, mais le scanne simplement pour les contrôles PropertyGrid
, en activant HelpVisible
.
/// <summary>
/// Allows the description pane of the PropertyGrid to be shown when editing a collection of items within a PropertyGrid.
/// </summary>
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);
}
}
}
Pour afficher ce en cours d'utilisation (notez l'utilisation de 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()
}
}
});
}
}
cela a fonctionné sur place - merci – benPearce