Пример #1
0
        /// <summary>
        /// 拷贝
        /// </summary>
        public override object Clone()
        {
            TDataGridViewButtonColumn column = (TDataGridViewButtonColumn)base.Clone();

            column.Button = Button;
            return(column);
        }
Пример #2
0
        private void AutoColumns(Type type)
        {
            if (type == null || type == typeof(string) || type.IsValueType)
            {
                return;
            }
            Type iType = type.GetInterface(typeof(IParent).FullName);

            if (iType == null)
            {
                throw new ArgumentException("Data type error, interface not implemented: IParentId.");
            }

            Columns.Clear();
            var iTree   = false;
            var iColumn = TextColumn != null && type.Property(TextColumn) != null;

            foreach (var property in type.PropertiesValue())
            {
                var visible = property.IShow();
                DataGridViewColumn column;
                if (!iTree && ((!iColumn && visible) || (iColumn && TextColumn.Equals(property.Name, StringComparison.OrdinalIgnoreCase))))
                {
                    iTree  = true;
                    column = new TreeGridColumn();
                }
                else
                {
                    Type dbType = property.PropertyType;
                    if (dbType.IsGenericType)
                    {
                        dbType = Nullable.GetUnderlyingType(dbType);
                    }
                    if (dbType == typeof(Image) || dbType == typeof(Bitmap))
                    {
                        column = new DataGridViewImageColumn();
                    }
                    else if (property.ICheckBox())
                    {
                        column = new TDataGridViewCheckBoxColumn();
                    }
                    else if (property.IButton(out IButtonAttribute button))
                    {
                        column = new TDataGridViewButtonColumn(button);
                    }
                    else
                    {
                        column = new DataGridViewTextBoxColumn();
                    }
                }
                column.Visible    = visible;
                column.HeaderText = property.Text();
                column.Name       = property.Name;
                Columns.Add(column);
            }
        }
Пример #3
0
        /// <summary>
        /// 更新列名称
        /// </summary>
        internal void UpdateColumns(Type type)
        {
            if (type == null || type == typeof(string) || type.IsValueType)
            {
                return;
            }
            this.type = type;

            var properties = type.PropertiesCache();

            for (var i = 0; i < Columns.Count; i++)
            {
                var column   = Columns[i];
                var property = properties.Property(column.Name);
                if (property == null)
                {
                    continue;
                }
                if (property.ICheckBox())
                {
                    column = new TDataGridViewCheckBoxColumn
                    {
                        Name             = Columns[i].Name,
                        DataPropertyName = Columns[i].DataPropertyName,
                        DisplayIndex     = Columns[i].DisplayIndex
                    };
                    Columns.RemoveAt(i);
                    Columns.Insert(i, column);
                }
                else if (property.IButton(out IButtonAttribute button))
                {
                    column = new TDataGridViewButtonColumn(button)
                    {
                        Name             = Columns[i].Name,
                        DataPropertyName = Columns[i].DataPropertyName,
                        DisplayIndex     = Columns[i].DisplayIndex
                    };
                    Columns.RemoveAt(i);
                    Columns.Insert(i, column);
                }
                column.Visible    = property.IShow();
                column.HeaderText = property.Text();
            }
        }