private DataGridViewColumn AddColumn(String propertyName, String headerText, Type dataType) { var column = new DataGridViewTextBoxColumn(); column.DataPropertyName = propertyName; column.HeaderText = headerText; column.ValueType = dataType; column.Resizable = DataGridViewTriState.True; column.SortMode = DataGridViewColumnSortMode.Automatic; // needed because otherwise all non text columns will not be sortable if (TypeFns.IsNumericType(dataType)) { column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight; column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; } else if (dataType == typeof(DateTime)) { column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight; column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; column.DefaultCellStyle.Format = "G"; // short date, long time } mDataGridView.Columns.Add(column); return(column); }
public static PropertyMetadata GetPropertyMetadata(IProperty prop) { var type = prop.ClrType; var nullable = prop.IsNullable; var isPartOfKey = prop.IsKey(); var underliningType = Nullable.GetUnderlyingType(type); if (underliningType != null) { type = underliningType; } var isEnum = type.IsEnum; var numeric = TypeFns.IsNumericType(type); var dataType = isEnum ? "String" : ShortTypeNameFromLongName(type.Name); object defaultValue = null; if (nullable != true && numeric) { defaultValue = 0; } if (nullable != true && type == typeof(string)) { defaultValue = ""; } return(new PropertyMetadata { Name = ToCamelCase(prop.Name), EnumType = isEnum ? type.FullName : null, IsNullable = nullable, DefaultValue = defaultValue, DataType = dataType, IsPartOfKey = isPartOfKey }); }