/*internal override void OnItemRemoving(object item)
         * {
         *      ListView instance = base.Context.Instance as ListView;
         *      if (instance != null)
         *      {
         *              ColumnHeaderEx column = item as ColumnHeaderEx;
         *              if (column != null)
         *              {
         *                      IComponentChangeService service = base.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
         *                      PropertyDescriptor member = null;
         *                      if (service != null)
         *                      {
         *                              member = TypeDescriptor.GetProperties(base.Context.Instance)["Columns"];
         *                              service.OnComponentChanging(base.Context.Instance, member);
         *                      }
         *                      instance.Columns.Remove(column);
         *                      if ((service != null) && (member != null))
         *                      {
         *                              service.OnComponentChanged(base.Context.Instance, member, null, null);
         *                      }
         *              }
         *      }
         * }*/

        protected override object SetItems(object editValue, object[] value)
        {
            if (editValue != null)
            {
                ColumnHeaderExCollection headers = editValue as ColumnHeaderExCollection;
                if (headers != null)
                {
                    headers.Clear();
                    ColumnHeaderEx[] destinationArray = new ColumnHeaderEx[value.Length];
                    Array.Copy(value, 0, destinationArray, 0, value.Length);
                    headers.AddRange(destinationArray);
                }
            }
            return(editValue);
        }
Esempio n. 2
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException(nameof(destinationType));
            }

            if (!(destinationType == typeof(InstanceDescriptor)) || !(value is ColumnHeaderEx))
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }

            ColumnHeaderEx     header         = (ColumnHeaderEx)value;
            Type               reflectionType = TypeDescriptor.GetReflectionType(value);
            ConstructorInfo    constructor;
            InstanceDescriptor descriptor = null;

            if (header.ImageIndex != -1)
            {
                constructor = reflectionType.GetConstructor(new Type[] { typeof(int) });
                if (constructor != null)
                {
                    descriptor = new InstanceDescriptor(constructor, new object[] { header.ImageIndex }, false);
                }
            }

            if ((descriptor == null) && !string.IsNullOrEmpty(header.ImageKey))
            {
                constructor = reflectionType.GetConstructor(new Type[] { typeof(string) });
                if (constructor != null)
                {
                    descriptor = new InstanceDescriptor(constructor, new object[] { header.ImageKey }, false);
                }
            }

            if (descriptor != null)
            {
                return(descriptor);
            }

            constructor = reflectionType.GetConstructor(Type.EmptyTypes);
            if (constructor == null)
            {
                throw new ArgumentException("NoDefaultConstructor");
            }

            return(new InstanceDescriptor(constructor, new object[0], false));
        }
Esempio n. 3
0
        protected virtual ListViewItem BuildItem(object obj)
        {
            var items = new string[Columns.Count];

            for (int i = 0; i < Columns.Count; i++)
            {
                ColumnHeaderEx hdr = Columns[i];
                var            pd  = dataSourceProperties.Find(hdr.Name, false);
                if (pd != null)
                {
                    var val = pd.GetValue(obj);
                    if (val == null || val is DBNull)
                    {
                        items[i] = hdr.NullValue;
                    }
                    else
                    {
                        var formattable = val as IFormattable;
                        if (formattable == null)
                        {
                            var customFormatter = hdr.FormatProvider as ICustomFormatter;
                            if (customFormatter == null)
                            {
                                items[i] = Convert.ToString(pd.GetValue(obj), hdr.FormatProvider);
                            }
                            else
                            {
                                items[i] = customFormatter.Format(hdr.Format, pd.GetValue(obj), hdr.FormatProvider);
                            }
                        }
                        else
                        {
                            items[i] = formattable.ToString(hdr.Format, hdr.FormatProvider);
                        }
                    }
                    continue;
                }
                if (dataSourceProperties.Count > i)
                {
                    items[i] = Convert.ToString(dataSourceProperties[i].GetValue(obj));
                }
            }
            return(new ListViewItem(items));
        }
Esempio n. 4
0
        public new object Clone()
        {
            ColumnHeaderEx header = new ColumnHeaderEx()
            {
                Text = Text, TextAlign = TextAlign, Width = Width
            };

            header.DropDownContextMenu = DropDownContextMenu;
            header.Format             = Format;
            header.FormatProvider     = FormatProvider;
            header.Hideable           = Hideable;
            header.NullValue          = NullValue;
            header.ShowDropDownButton = ShowDropDownButton;
            header.Sortable           = Sortable;
            header.SortOrder          = SortOrder;
            header.Tag = (Tag is ICloneable) ? ((ICloneable)Tag).Clone() : Tag;
            header.Extras.GroupingInfo = (Extras.GroupingInfo is ICloneable) ? ((ICloneable)Extras.GroupingInfo).Clone() : Extras.GroupingInfo;
            return(header);
        }
Esempio n. 5
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            ColumnHeader hdr = value as ColumnHeader;

            if (hdr == null)
            {
                return(base.ConvertFrom(context, culture, value));
            }

            var header = new ColumnHeaderEx {
                Text = hdr.Text, TextAlign = hdr.TextAlign, Width = hdr.Width
            };

            // TODO: missing ImageList and index and owner ListView
            header.Tag = hdr.Tag;
            return(header);
        }