public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { Type type = Barcodes.GetType((string)value); return(type == null ? null : Activator.CreateInstance(type)); } return(base.ConvertFrom(context, culture, value)); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object Value) { edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); string name = (Value as BarcodeBase).Name; ListBox lb = new ListBox(); lb.Items.AddRange(Barcodes.GetItems()); lb.SelectedItem = name; lb.BorderStyle = BorderStyle.None; lb.Height = lb.ItemHeight * lb.Items.Count; lb.Click += new EventHandler(lb_Click); edSvc.DropDownControl(lb); string selectedName = (string)lb.SelectedItem; if (selectedName != name) { return(Activator.CreateInstance(Barcodes.GetType(selectedName))); } return(Value); }