Hashtable stuff = new Hashtable();
stuff["Other"] = "Thanks for the fish";
stuff["Thing"] = SystemIcons.Asterisk;
dictionary["Stuff"] = stuff;
DictionaryPropertyGridAdapter.GetProperties should look like this:
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
List properties = new List();
foreach (DictionaryEntry entry in _dictionary)
{
Attribute[] propertyAttributes = null;
if (typeof(IDictionary).IsAssignableFrom(entry.Value.GetType()))
{
propertyAttributes = new Attribute[] { new EditorAttribute(typeof(DictionaryEditor), typeof(UITypeEditor)) };
}
properties.Add(new DictionaryPropertyDescriptor(_dictionary, entry.Key, propertyAttributes));
}
return new PropertyDescriptorCollection(properties.ToArray());
}
DictionaryEditor looks like this:
public class DictionaryEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
// Gives us an ellipsis, rather than a drop-down arrow. Otherwise, it's pretty much cosmetic.
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
if (value is IDictionary)
{
DictionaryPropertyGridForm form = new DictionaryPropertyGridForm((IDictionary)value);
form.ShowDialog();
}
return value;
}
}
Yep, that seems to work...
In Main...
Hashtable stuff = new Hashtable(); stuff["Other"] = "Thanks for the fish"; stuff["Thing"] = SystemIcons.Asterisk; dictionary["Stuff"] = stuff;DictionaryPropertyGridAdapter.GetProperties should look like this:
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { List properties = new List(); foreach (DictionaryEntry entry in _dictionary) { Attribute[] propertyAttributes = null; if (typeof(IDictionary).IsAssignableFrom(entry.Value.GetType())) { propertyAttributes = new Attribute[] { new EditorAttribute(typeof(DictionaryEditor), typeof(UITypeEditor)) }; } properties.Add(new DictionaryPropertyDescriptor(_dictionary, entry.Key, propertyAttributes)); } return new PropertyDescriptorCollection(properties.ToArray()); }DictionaryEditor looks like this:
public class DictionaryEditor : UITypeEditor { public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) { // Gives us an ellipsis, rather than a drop-down arrow. Otherwise, it's pretty much cosmetic. return UITypeEditorEditStyle.Modal; } public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value) { if (value is IDictionary) { DictionaryPropertyGridForm form = new DictionaryPropertyGridForm((IDictionary)value); form.ShowDialog(); } return value; } }