private void buttonOK_Click(object sender, EventArgs e)
 {
     try
     {
         if (listBox1.SelectedIndex >= 0)
         {
             DataEditor             de  = (DataEditor)Activator.CreateInstance((Type)(listBox1.Items[listBox1.SelectedIndex]));
             DlgSetEditorAttributes dlg = de.GetDataDialog(SelectedEditor);
             if (dlg != null)
             {
                 dlg.SetEditorAttributes(SelectedEditor);
                 if (dlg.ShowDialog(this) == DialogResult.OK)
                 {
                     SetSelection(de);
                     this.DialogResult = DialogResult.OK;
                 }
             }
             else
             {
                 this.DialogResult = DialogResult.OK;
             }
         }
     }
     catch (Exception err)
     {
         MessageBox.Show(err.Message);
     }
 }
예제 #2
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             FieldEditorList felst = context.Instance as FieldEditorList;
             if (felst != null)
             {
                 DataEditorListBox list = new DataEditorListBox(edSvc);
                 edSvc.DropDownControl(list);
                 if (list.Selector != null)
                 {
                     if (list.Selector is DataEditorNone)
                     {
                         value = null;
                         felst.RemoveEditorByName(context.PropertyDescriptor.Name);
                     }
                     else
                     {
                         list.Selector.ValueField = context.PropertyDescriptor.Name;
                         list.Selector.SetFieldsAttribute(felst.Fields);
                         DataEditor             current = value as DataEditor;
                         DlgSetEditorAttributes dlg     = list.Selector.GetDataDialog(current);
                         if (dlg != null)
                         {
                             if (edSvc.ShowDialog(dlg) == DialogResult.OK)
                             {
                                 dlg.SelectedEditor.ValueField = context.PropertyDescriptor.Name;
                                 current = (DataEditor)dlg.SelectedEditor.Clone();
                                 value   = current;
                                 felst.AddEditor(current);
                             }
                         }
                         else
                         {
                             current = (DataEditor)list.Selector.Clone();
                             value   = list.Selector;
                             felst.AddEditor(current);
                         }
                     }
                 }
             }
         }
     }
     return(value);
 }