public void Insert(int index, PropertyGridRow value)
 {
     if (this.Contains(value.PropertyName) == false)
     {
         List.Insert(index, value);
     }
 }
 public void AddPropertyGirdRow(PropertyGridRow propertyGirdRow, string catalogName)
 {
     if (!Contains(catalogName))
     {
         Add(catalogName);
     }
     this[catalogName].SubRows.Add(propertyGirdRow);
 }
Example #3
0
 public ObjectPropertyValueChangedEventArgs(object rootObject, object obj, string property, object oldValue, object newValue, PropertyGridRow row)
 {
     this.RootObject    = rootObject;
     this._targetObject = obj;
     this.Property      = property;
     this.OldValue      = oldValue;
     this.NewValue      = newValue;
     this._row          = row;
 }
        private void dataGridViewProperty_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (this._updateSelectedObject == false)
            {
                return;
            }

            if (this.propertyGridDataGridView.SelectedObjectSeting)
            {
                return;
            }

            //更新子行的值是,这个事件会触发两次,并不是一次父行一次子行触发
            //而是在通知父行在更新值是,父行会自动更新其下子行,就又一次进来
            //更新子行时子行去更新父行,不会使父行进入这个事件
            //为了避免子行两次进来,增加一个valueChanging属性

            //首先判断是否是一个实现了IPropertyGirdCell接口的属性编辑单元格
            IPropertyGirdCell iPropertyGirdCell = this.propertyGridDataGridView[e.ColumnIndex, e.RowIndex] as IPropertyGirdCell;

            if (iPropertyGirdCell == null)
            {
                return;
            }

            PropertyGridRow propertyGirdRow = this.propertyGridDataGridView.Rows[e.RowIndex] as PropertyGridRow;

            //如果是自己引发的更新
            if (propertyGirdRow.ValueChangingBySelf)
            {
                return;
            }

            //如果当前行是子行,设置ValueChangingBySelf=true,表示接下来由于 UpdateSelectedObject 再次进入的这个事件
            //是自己引发的
            //保证PropertyChanged委托只调用一次
            if (propertyGirdRow.ParentRow != null)
            {
                propertyGirdRow.ValueChangingBySelf = true;
            }

            propertyGirdRow.ContrastDefaultValue();
            propertyGirdRow.UpdateSelectedObject();

            //调用属性已更改事件
            if (this.PropertyChanged != null)
            {
                PropertyChangeEventArgs eventArgs = new PropertyChangeEventArgs(this.SelectedObjects, propertyGirdRow);
                PropertyChanged(sender, eventArgs);

                Debug.WriteLine("PropertyChanged > CellValueChanged : " + propertyGirdRow.PropertyName);
            }

            propertyGirdRow.ValueChangingBySelf = false;
        }
 public int Add(PropertyGridRow value)
 {
     if (this.Contains(value.PropertyName) == false)
     {
         return(List.Add(value));
     }
     else
     {
         return(this.Count);
     }
 }
Example #6
0
        public PropertyGridRow[] GetPropertyGridRow(Type type)
        {
            var items = from c in _items where c.Type.Equals(type) select c;

            PropertyGridRowCacheItem[] cachedItems = items.ToArray();
            PropertyGridRow[]          rows        = new PropertyGridRow[cachedItems.Length];
            for (int i = 0; i < cachedItems.Length; i++)
            {
                rows[i] = cachedItems[i].PropertyGridRow;
            }
            return(rows);
        }
        /// <summary>
        /// 选中的对象的属性(property)值 发生改变
        /// 此方法由属性行调用
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="propertyName"></param>
        /// <param name="oldValue"></param>
        /// <param name="newValue"></param>
        /// <param name="row"></param>
        internal void PropertyValueChanage(object rootObject, object targetObject, string propertyName, object oldValue, object newValue,
                                           PropertyGridRow row)
        {
            if (rootObject == null || targetObject == null || propertyName == null || propertyName == String.Empty)
            {
                throw new ArgumentNullException();
            }

            if (ObjectPropertyValueChanged != null)
            {
                ObjectPropertyValueChangedEventArgs eventArgs =
                    new ObjectPropertyValueChangedEventArgs(rootObject, targetObject, propertyName, oldValue, newValue, row);
                ObjectPropertyValueChanged(this, eventArgs);
            }
        }
        /// <summary>
        /// 初始化子属性行
        /// </summary>
        private void InitSubRow()
        {
            if (this.SubRows != null)
            {
                this.SubRows.Clear();
            }

            if (this._propertyInfo == null)
            {
                return;
            }

            //看这个属性对象是否还有需要初始化为子属性行的属性(Property)
            foreach (PropertyInfo propertyInfoChild in this._propertyInfo.PropertyType.GetProperties())
            {
                PropertyRelatorAttribute propertyGirdAttribute = null;

                PropertyRelatorAttribute[] attributes = (PropertyRelatorAttribute[])propertyInfoChild.GetCustomAttributes(typeof(PropertyRelatorAttribute), true);
                if (attributes == null || attributes.Length == 0)
                {
                    continue;
                }

                propertyGirdAttribute = attributes[0];

                //至此,确定这是一个要显示的子属性
                PropertyGridRow propertyGirdRowChild = new PropertyGridRow(propertyGirdAttribute, propertyInfoChild, this._propertyGrid);

                if (this.SubRows == null)
                {
                    this.SubRows = new List <PropertyGridRow>();
                }

                propertyGirdRowChild.ParentRow = this;

                this.SubRows.Add(propertyGirdRowChild);
            }
        }
        /// <summary>
        /// 初始化对象的属性行
        /// </summary>
        /// <param name="attribute"></param>
        private void InitializePropertyRow(Object obj)
        {
            Type type = obj.GetType();

            //将类型注册到行集合

            #region 判断类型是否已经缓存过属性行,如果有,使用缓存的行,然后return

            if (_propertyGirdRowCache.IsCached(type))
            {
                //使用缓存时有一个情况必须考虑,那就是行在当前情况下(如选择的对象个数)是否还有效的问题
                foreach (PropertyGridRow row in _propertyGirdRowCache.GetPropertyGridRow(type))
                {
                    //确保清除当前缓存的行上的对象选择
                    row.SetSelectedObjects(null);
                    if (row.CanVisible)
                    {
                        PropertyGridRows.Add(row);
                    }
                }

                return;
            }

            #endregion

            #region 迭代类型的Properties

            foreach (PropertyInfo propertyInfo in type.GetProperties())
            {
                PropertyRelatorAttribute propertyGirdAttribute = null;

                PropertyRelatorAttribute[] attributes = (PropertyRelatorAttribute[])propertyInfo.GetCustomAttributes(typeof(PropertyRelatorAttribute), true);
                if (attributes == null || attributes.Length == 0)
                {
                    continue;
                }

                propertyGirdAttribute = attributes[0];

                //至此,确定需要加载当前的属性行

                /*
                 * 原本会用一个if查找 PropertyGirdRowCollection 中是否已经有了同样(同名)的属性信息,如果有就不new新的行了,也不走到cache
                 * 这样有一个问题,如果一上来就多选了多个不同的对象,这些对象会有共有的属性(Property)
                 * 如果判断this.PropertyGridRows中有了就不new 新row,不cache这个新的row,就会造成缓存中被选中的一些类型的对象的属性行不完整
                 * 因为他们没有机会被初始化,被缓存,因为在走到他们的这些属性(propertyinfo时,其它对象同名的属性行已经被加到 this.PropertyGridRows中了
                 * 所以这里不能因为 this.PropertyGridRows中有了就不初始化不缓存
                 * this.PropertyGridRows.Add方法可以照调,方法内部会判断是否已经存在了同名的属性行
                 */
                PropertyGridRow propertyGirdRow = new PropertyGridRow(propertyGirdAttribute, propertyInfo, this);

                if (this.PropertyGridRows.Contains(propertyGirdRow.PropertyName) == false)
                {
                    this.PropertyGridRows.Add(propertyGirdRow);
                }

                _propertyGirdRowCache.Cache(new PropertyGridRowCacheItem(type, propertyGirdRow));
            }

            #endregion
        }
 public PropertyChangeEventArgs(object [] targetObject, PropertyGridRow row)
 {
     this._selectedObjects = targetObject;
     this._row             = row;
 }
 public void Remove(PropertyGridRow value)
 {
     List.Remove(value);
 }
 public int IndexOf(PropertyGridRow value)
 {
     return(List.IndexOf(value));
 }
 public bool Contains(PropertyGridRow value)
 {
     return(List.Contains(value));
 }
 public PropertyGridRowCacheItem(Type type, PropertyGridRow propertyGridRow)
 {
     Type            = type;
     PropertyGridRow = propertyGridRow;
 }