[.net] C# propertygrid-like array editing during run time

Started by
0 comments, last by alex_myrpg 15 years, 9 months ago
I'd like to be able to edit an array exactly how C#'s property grid handles them. The only catch is, I want to do it on my form during runtime and without it being in a propertygrid. Is there some easy way to do this?
Advertisement
I suspect you'll want to use the ArrayEditor object. Add a reference to System.Design to your project and add "using System.ComponentModel.Design" to import the namespace. You'll then want to do something like:

string[] myArray = new string[] { "item 1", "item 2", "item 3" };

ArrayEditor editor = new ArrayEditor(typeof(string));
editor.EditValue(null, myArray);

I've tested this code and although it doesn't work (no dialog is shown even though no exception is thrown), you should be able to get it working if you just find out what to pass to EditValue as the IServiceProvider (instead of null). I couldn't seem to find anything sensible to pass as a parameter, though you *may* be able to get the desired object from a property/function of the form (rather than creating your own). The Form.Site property is of type ISite (which inherits from IServiceProvider), but unfortunately this property seems to always be null at runtime, so no luck using that.

Delving into the .NET libraries with Reflector and reading over MSDN docs might give you your answer. Good luck...

This topic is closed to new replies.

Advertisement