Jump to content
  • Advertisement
Sign in to follow this  
gellin

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

This topic is 3698 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
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...

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!