示例#1
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null)
            {
                object instance = context.Instance;

                PropertyDescriptor imageListProp = ImageListUtils.GetImageListProperty(context.PropertyDescriptor, ref instance);

                while (instance != null && imageListProp is null)
                {
                    PropertyDescriptorCollection props = TypeDescriptor.GetProperties(instance);

                    foreach (PropertyDescriptor prop in props)
                    {
                        if (typeof(ImageList).IsAssignableFrom(prop.PropertyType))
                        {
                            imageListProp = prop;
                            break;
                        }
                    }

                    if (imageListProp is null)
                    {
                        // We didn't find the image list in this component.  See if the
                        // component has a "parent" property.  If so, walk the tree...
                        //
                        PropertyDescriptor parentProp = props[ParentImageListProperty];
                        if (parentProp != null)
                        {
                            instance = parentProp.GetValue(instance);
                        }
                        else
                        {
                            // Stick a fork in us, we're done.
                            //
                            instance = null;
                        }
                    }
                }

                if (imageListProp != null)
                {
                    ImageList imageList = (ImageList)imageListProp.GetValue(instance);

                    if (imageList != null)
                    {
                        // Create array to contain standard values
                        //
                        object[] values;
                        int      nImages = imageList.Images.Count;
                        if (IncludeNoneAsStandardValue)
                        {
                            values          = new object[nImages + 1];
                            values[nImages] = -1;
                        }
                        else
                        {
                            values = new object[nImages];
                        }

                        // Fill in the array
                        //
                        for (int i = 0; i < nImages; i++)
                        {
                            values[i] = i;
                        }

                        return(new StandardValuesCollection(values));
                    }
                }
            }

            if (IncludeNoneAsStandardValue)
            {
                return(new StandardValuesCollection(new object[] { -1 }));
            }
            else
            {
                return(new StandardValuesCollection(Array.Empty <object>()));
            }
        }
示例#2
0
 public DataGridTextBoxColumn(PropertyDescriptor prop, bool isDefault) : this(prop, null, isDefault)
 {
 }
        /// <devdoc>
        ///      Gets the best matching ctor for a given binding and fills it out, based on the
        ///      state of the Binding and the optimal ctor.
        /// </devdoc>
        private InstanceDescriptor GetInstanceDescriptorFromValues(Binding b)
        {
            // The BindingFormattingDialog turns on Binding::FormattingEnabled property.
            // however, when the user data binds a property using the PropertyBrowser, Binding::FormattingEnabled is set to false
            // The Binding class is not a component class, so we don't have the ComponentInitialize method where we can set FormattingEnabled to true
            // so we set it here.
            b.FormattingEnabled = true;

            bool isComplete = true;
            int  lastItem   = ConstructorParameterProperties.Length - 1;

            for (; lastItem >= 0; lastItem--)
            {
                // null means no prop is available, we quit here.
                //
                if (ConstructorParameterProperties[lastItem] == null)
                {
                    break;
                }

                // get the property and see if it needs to be serialized.
                //
                PropertyDescriptor prop = TypeDescriptor.GetProperties(b)[ConstructorParameterProperties[lastItem]];
                if (prop != null && prop.ShouldSerializeValue(b))
                {
                    break;
                }
            }

            // now copy the type array up to the point we quit.
            //
            Type[] ctorParams = new Type[lastItem + 1];
            Array.Copy(ConstructorParamaterTypes, 0, ctorParams, 0, ctorParams.Length);

            // Get the ctor info.
            //
            ConstructorInfo ctor = typeof(Binding).GetConstructor(ctorParams);

            Debug.Assert(ctor != null, "Failed to find Binding ctor for types!");
            if (ctor == null)
            {
                isComplete = false;
                ctor       = typeof(Binding).GetConstructor(new Type[] {
                    typeof(string),
                    typeof(object),
                    typeof(string)
                });
            }

            // now fill in the values.
            //
            object[] values = new object[ctorParams.Length];

            for (int i = 0; i < values.Length; i++)
            {
                object val = null;
                switch (i)
                {
                case 0:
                    val = b.PropertyName;
                    break;

                case 1:
                    val = b.BindToObject.DataSource;
                    break;

                case 2:
                    val = b.BindToObject.BindingMemberInfo.BindingMember;
                    break;

                default:
                    val = TypeDescriptor.GetProperties(b)[ConstructorParameterProperties[i]].GetValue(b);
                    break;
                }
                values[i] = val;
            }
            return(new InstanceDescriptor(ctor, values, isComplete));
        }
示例#4
0
 public DataGridTextBoxColumn(PropertyDescriptor prop)
     : this(prop, null, false)
 {
 }
示例#5
0
 public DataGridTextBoxColumn(PropertyDescriptor prop, string format) : this(prop, format, false)
 {
 }
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null)
            {
                object instance = context.Instance;

                ImageList imageList = null;

                PropertyDescriptorCollection listViewItemProps = TypeDescriptor.GetProperties(instance);
                PropertyDescriptor           listViewProp      = listViewItemProps["ListView"];

                if (listViewProp != null)
                {
                    // Grab the ListView property off of the TreeNode.
                    object listViewInstance = listViewProp.GetValue(instance);

                    if (listViewInstance != null)
                    {
                        // Get the ImageList property from the ListView and set it to be the currentImageList.
                        PropertyDescriptorCollection listViewProps             = TypeDescriptor.GetProperties(listViewInstance);
                        PropertyDescriptor           listViewImageListProperty = listViewProps["StateImageList"];
                        if (listViewImageListProperty != null)
                        {
                            imageList = (ImageList)listViewImageListProperty.GetValue(listViewInstance);
                        }
                    }
                }

                if (imageList != null)
                {
                    // Create array to contain standard values
                    object[] values;
                    int      nImages = imageList.Images.Count;
                    if (IncludeNoneAsStandardValue)
                    {
                        values          = new object[nImages + 1];
                        values[nImages] = ImageList.Indexer.DefaultIndex;
                    }
                    else
                    {
                        values = new object[nImages];
                    }

                    // Fill in the array
                    for (int i = 0; i < nImages; i++)
                    {
                        values[i] = i;
                    }

                    return(new StandardValuesCollection(values));
                }
            }

            if (IncludeNoneAsStandardValue)
            {
                return(new StandardValuesCollection(new object[] { ImageList.Indexer.DefaultIndex }));
            }
            else
            {
                return(new StandardValuesCollection(Array.Empty <object>()));
            }
        }
示例#7
0
 object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
 {
     throw null;
 }
        internal BindingManagerBase EnsureListManager(object dataSource, string dataMember)
        {
            if (dataMember == null)
            {
                dataMember = "";
            }
            HashKey            key = GetKey(dataSource, dataMember);
            WeakReference      wRef;
            BindingManagerBase bindingManagerBase = null;

            wRef = listManagers[key] as WeakReference;
            if (wRef != null)
            {
                bindingManagerBase = (BindingManagerBase)wRef.Target;
            }
            if (bindingManagerBase != null)
            {
                return(bindingManagerBase);
            }

            // create base listManager.
            if (dataMember.Length == 0)
            {
                //IListSource so we can bind the dataGrid to a table and a dataSet
                if (dataSource is IList || dataSource is IListSource)
                {
                    bindingManagerBase = new CurrencyManager(dataSource);
                }
                else
                {
                    bindingManagerBase = new PropertyManager(dataSource);
                }

                // if wRef == null, then it is the first time we want this bindingManagerBase: so add it
                // if wRef != null, then the bindingManagerBase was GC'ed at some point: keep the old wRef and change its target
                if (wRef == null)
                {
                    listManagers.Add(key, new WeakReference(bindingManagerBase, false));
                }
                else
                {
                    wRef.Target = bindingManagerBase;
                }
                return(bindingManagerBase);
            }

            // handle relation.
            int lastDot = dataMember.LastIndexOf(".");
            BindingManagerBase formerManager = EnsureListManager(dataSource, lastDot == -1 ? "" : dataMember.Substring(0, lastDot));
            PropertyDescriptor prop          = formerManager.GetItemProperties().Find(dataMember.Substring(lastDot + 1), true);

            if (prop == null)
            {
                throw new ArgumentException(SR.GetString(SR.RelatedListManagerChild, dataMember.Substring(lastDot + 1)));
            }
            if (typeof(IList).IsAssignableFrom(prop.PropertyType))
            {
                bindingManagerBase = new RelatedCurrencyManager(formerManager, dataMember.Substring(lastDot + 1));
            }
            else
            {
                bindingManagerBase = new RelatedPropertyManager(formerManager, dataMember.Substring(lastDot + 1));
            }

            // if wRef == null, then it is the first time we want this bindingManagerBase: so add it
            // if wRef != null, then the bindingManagerBase was GC'ed at some point: keep the old wRef and change its target
            if (wRef == null)
            {
                listManagers.Add(GetKey(dataSource, dataMember), new WeakReference(bindingManagerBase, false));
            }
            else
            {
                wRef.Target = bindingManagerBase;
            }
            return(bindingManagerBase);
        }
 /// <include file='doc\DataGridBoolColumn.uex' path='docs/doc[@for="DataGridBoolColumn.DataGridBoolColumn2"]/*' />
 public DataGridBoolColumn(PropertyDescriptor prop, bool isDefault)
     : base(prop, isDefault)
 {
 }
示例#10
0
 /// <include file='doc\DataGridBoolColumn.uex' path='docs/doc[@for="DataGridBoolColumn.DataGridBoolColumn1"]/*' />
 /// <devdoc>
 /// <para>Initializes a new instance of a <see cref='System.Windows.Forms.DataGridBoolColumn'/> with the specified <see cref='System.Data.DataColumn'/>.</para>
 /// </devdoc>
 public DataGridBoolColumn(PropertyDescriptor prop)
     : base(prop)
 {
 }