Advertisement Jump to content
Sign in to follow this  

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

This topic is 3856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post

Link to post
Share on other sites
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...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!