S
Sebastien Lange
Hi,
I want to edit a property (type=string[]) in the propertygrid. Usually you
use StringArrayEditor.
But I'd like to change the instruction displayed in the StringCollectionForm
and the text of the form.
Unfortunaltely, StringArrayEditor is internal, so I can't inherit.
I tried to inherit from CollectionEditor and then provide
StringCollectionForm (see hereafter). So I can change the instruction and
text (thanks to reflection). But if I change the collection (add a string, I
get an 'object reference not set to...' outside of my code.
Do you see a better way to do it? What's wrong? I know I can create my own
MyStringCollectionForm, but I don't want to do that.
Any idea?
Sebastien
public class TheObject{
[Editor(typeof(OutputArrayEditor), typeof(UITypeEditor))]
public string[] TheProperty{
...
}
}
public class OutputArrayEditor : CollectionEditor //ideal would be
StringArrayEditor
{
public OutputArrayEditor(Type type) : base (type){}
protected override
System.ComponentModel.Design.CollectionEditor.CollectionForm
CreateCollectionForm()
{
Type editorType =
Type.GetType("System.Windows.Forms.Design.StringArrayEditor, System.Design,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
object editor = editorType.InvokeMember(null, BindingFlags.CreateInstance,
null, null, new object[]{typeof(string[])});
Form form = (Form)editorType.InvokeMember("CreateCollectionForm",
BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance,
null, editor, null);
form.Text = "My Custom collection text";
//add code to chg instruction here (reflection)
return (CollectionEditor.CollectionForm)form;//base.CreateCollectionForm
();
}
protected override object SetItems(object editValue, object[] value)
{
return base.SetItems (editValue, value);
}
protected override object[] GetItems(object editValue)
{
return base.GetItems (editValue);
}
}
I want to edit a property (type=string[]) in the propertygrid. Usually you
use StringArrayEditor.
But I'd like to change the instruction displayed in the StringCollectionForm
and the text of the form.
Unfortunaltely, StringArrayEditor is internal, so I can't inherit.
I tried to inherit from CollectionEditor and then provide
StringCollectionForm (see hereafter). So I can change the instruction and
text (thanks to reflection). But if I change the collection (add a string, I
get an 'object reference not set to...' outside of my code.
Do you see a better way to do it? What's wrong? I know I can create my own
MyStringCollectionForm, but I don't want to do that.
Any idea?
Sebastien
public class TheObject{
[Editor(typeof(OutputArrayEditor), typeof(UITypeEditor))]
public string[] TheProperty{
...
}
}
public class OutputArrayEditor : CollectionEditor //ideal would be
StringArrayEditor
{
public OutputArrayEditor(Type type) : base (type){}
protected override
System.ComponentModel.Design.CollectionEditor.CollectionForm
CreateCollectionForm()
{
Type editorType =
Type.GetType("System.Windows.Forms.Design.StringArrayEditor, System.Design,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
object editor = editorType.InvokeMember(null, BindingFlags.CreateInstance,
null, null, new object[]{typeof(string[])});
Form form = (Form)editorType.InvokeMember("CreateCollectionForm",
BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance,
null, editor, null);
form.Text = "My Custom collection text";
//add code to chg instruction here (reflection)
return (CollectionEditor.CollectionForm)form;//base.CreateCollectionForm
();
}
protected override object SetItems(object editValue, object[] value)
{
return base.SetItems (editValue, value);
}
protected override object[] GetItems(object editValue)
{
return base.GetItems (editValue);
}
}