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); } }