title: How do I create a Modal UITypeEditor for a string property?
body: <p>I have a property which is stored as a string and is to be edited via a PropertyGrid  It is kept as a set of comma separated values e.g ABC, DEF, GHI.  My users could edit the string directly but the values come from a closed set of values.  So it is easier and safer for them to pick from a list.</p>
  
  <p>I have written a simple custom UITypeEditor based on the excellent answer <a href="https://stackoverflow.com/questions/1016239/how-to-create-custom-propertygrid-editor-item-which-opens-a-form">here</a></p>
  
  <p>I also reviewed <a href="https://stackoverflow.com/questions/6538293/property-set-isnt-being-triggered-with-a-uitypeeditor-implemented">this</a> but I did not really understand it might relate to my problem. 8-(</p>
  
  <p>I set up a simple form that allows the user to pick from a list and the picked values are added to value to be returned.  My problem is that the value is not being returned.  I wondered if this is something to do with the immutability of strings.  However it is probably something simple and stupid that I am doing.</p>
  
  <p>Here is my code for the type editor based on Marc's answer:</p>
  
  <pre><code>   public class AirlineCodesEditor : UITypeEditor
      {
  
          public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
          {
              return UITypeEditorEditStyle.Modal;
          }
  
          public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
          {
              var svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
              var codes = value as string;
  
              if (svc != null &amp;&amp; codes != null)
              {
                  using (var form = new AirlineCodesEditorGUI())
                  {
                      form.Value = codes;
                      if (svc.ShowDialog(form) == DialogResult.OK)
                      {
                          codes = form.Value; // update object
                      }
                  }
              }
  
              return value; // can also replace the wrapper object here
          }
  
      }
  </code></pre>
  
  <p>The form is trivial for my test I just edited the textbox with some new values:</p>
  
  <pre><code>   public partial class AirlineCodesEditorGUI : Form
      {
  
  
          public AirlineCodesEditorGUI()
          {
              InitializeComponent();
  
          }
  
  
          public string Value {
              get
              {
                  return airlineCodes.Text;
              }
  
              set
              {
                  airlineCodes.Text = value;
              } 
          }
  
          private void OnCloseButtonClick(object sender, System.EventArgs e)
          {
              DialogResult = DialogResult.OK;
              Close();
          }
      }  
  </code></pre>
  
  <p>Perhaps someone would put me out of my misery.</p>