Esempio n. 1
0
 public void LoadData(StringCollection names, string title, TypedNamedValue defaultValue, Dictionary <string, Type> types, bool validateName)
 {
     _validateName    = validateName;
     _useDefaultTypes = false;
     _names           = names;
     imgs             = new Dictionary <Type, Image>();
     listBox1.Items.Clear();
     _types = types;
     foreach (string s in types.Keys)
     {
         listBox1.Items.Add(s);
     }
     if (!string.IsNullOrEmpty(title))
     {
         this.Text = title;
     }
     if (defaultValue != null)
     {
         _oldName      = defaultValue.Name;
         textBox1.Text = defaultValue.Name;
         for (int i = 0; i < listBox1.Items.Count; i++)
         {
             Type t = _types[listBox1.Items[i] as string];
             if (t.Equals(defaultValue.Value.ValueType))
             {
                 listBox1.SelectedIndex = i;
                 break;
             }
         }
     }
     if (listBox1.SelectedIndex < 0)
     {
         listBox1.SelectedIndex = 0;
     }
 }
 public PropertyDescriptorNamedValue(string name, Attribute[] attrs, string category, TypedNamedValue data, Type componentType)
     : base(name, attrs)
 {
     _category      = category;
     _data          = data;
     _componentType = componentType;
 }
Esempio n. 3
0
 public void LoadData(StringCollection names, string title, TypedNamedValue defaultValue)
 {
     _validateName    = true;
     _useDefaultTypes = true;
     _names           = names;
     imgs             = null;
     if (!string.IsNullOrEmpty(title))
     {
         this.Text = title;
     }
     if (defaultValue != null)
     {
         _oldName      = defaultValue.Name;
         textBox1.Text = defaultValue.Name;
         if (typeof(string).Equals(defaultValue.Value.ValueType))
         {
             listBox1.SelectedIndex = 0;
         }
         else if (typeof(Int32).Equals(defaultValue.Value.ValueType))
         {
             listBox1.SelectedIndex = 1;
         }
         else if (typeof(double).Equals(defaultValue.Value.ValueType))
         {
             listBox1.SelectedIndex = 2;
         }
         else if (typeof(bool).Equals(defaultValue.Value.ValueType))
         {
             listBox1.SelectedIndex = 3;
         }
         else if (typeof(DateTime).Equals(defaultValue.Value.ValueType))
         {
             listBox1.SelectedIndex = 4;
         }
     }
 }
 public PropertyDescriptorValue(bool readOnly, TypedNamedValue owner, Attribute[] attrs)
     : base("Value", attrs)
 {
     _readOnly = readOnly;
     _owner    = owner;
 }
Esempio n. 5
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)
                {
                    ITypedNamedValuesHolder vep = context.Instance as ITypedNamedValuesHolder;
                    if (vep != null)
                    {
                        CommandList list = new CommandList(edSvc);
                        edSvc.DropDownControl(list);
                        if (list.MadeSelection)
                        {
                            bool edited = false;
                            switch (list.Selection)
                            {
                            case 0:
                                DlgNewTypedNamedValue dlg = new DlgNewTypedNamedValue();
                                TypedNamedValue       tn  = vep.GetTypedNamedValueByName(context.PropertyDescriptor.Name);
                                dlg.LoadData(vep.GetValueNames(), "Modify value name and type", tn);
                                if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                                {
                                    edited = vep.RenameTypedNamedValue(context.PropertyDescriptor.Name, dlg.DataName, dlg.DataType);
                                }
                                break;

                            case 1:
                                DlgText dlgt = new DlgText();
                                dlgt.LoadData(value as string, string.Format(CultureInfo.InvariantCulture, "Modify {0}", context.PropertyDescriptor.Name));
                                if (edSvc.ShowDialog(dlgt) == DialogResult.OK)
                                {
                                    value = dlgt.GetText();
                                }
                                break;

                            case 2:
                                edited = vep.DeleteTypedNamedValue(context.PropertyDescriptor.Name);
                                break;
                            }
                            if (edited)
                            {
                                PropertyGrid pg   = null;
                                Type         t    = edSvc.GetType();
                                PropertyInfo pif0 = t.GetProperty("OwnerGrid");
                                if (pif0 != null)
                                {
                                    object g = pif0.GetValue(edSvc, null);
                                    pg = g as PropertyGrid;
                                    if (pg != null)
                                    {
                                        pg.Refresh();
                                    }
                                }
                                PropertyDescriptorCollection ps = TypeDescriptor.GetProperties(context.Instance, true);
                                PropertyDescriptor           p  = ps["Dummy"];
                                if (p != null)
                                {
                                    p.SetValue(context.Instance, Guid.NewGuid().GetHashCode());
                                }
                                IPropertyListchangeable plc = context.Instance as IPropertyListchangeable;
                                if (plc != null)
                                {
                                    plc.OnPropertyListChanged();
                                }
                            }
                        }
                    }
                }
            }
            return(value);
        }