private static OLVColumn MakeColumnFromAttribute(string aspectName, OLVColumnAttribute attr, bool editable) { string title = attr.Title; if (string.IsNullOrEmpty(title)) { title = aspectName; } OLVColumn column = new OLVColumn(title, aspectName) { AspectToStringFormat = attr.AspectToStringFormat, CheckBoxes = attr.CheckBoxes, DisplayIndex = attr.DisplayIndex, GroupWithItemCountFormat = attr.GroupWithItemCountFormat, GroupWithItemCountSingularFormat = attr.GroupWithItemCountSingularFormat, Hyperlink = attr.Hyperlink, ImageAspectName = attr.ImageAspectName }; if (attr.IsEditableSet) { column.IsEditable = attr.IsEditable; } else { column.IsEditable = editable; } column.IsTileViewColumn = attr.IsTileViewColumn; column.UseInitialLetterForGroup = attr.UseInitialLetterForGroup; column.ToolTipText = attr.ToolTipText; column.IsVisible = attr.IsVisible; column.FillsFreeSpace = attr.FillsFreeSpace; if (attr.FreeSpaceProportion.HasValue) { column.FreeSpaceProportion = attr.FreeSpaceProportion.Value; } column.MaximumWidth = attr.MaximumWidth; column.MinimumWidth = attr.MinimumWidth; column.Width = attr.Width; column.Text = attr.Title; column.TextAlign = attr.TextAlign; column.Tag = attr.Tag; column.TriStateCheckBoxes = attr.TriStateCheckBoxes; if ((attr.GroupCutoffs != null) && (attr.GroupDescriptions != null)) { column.MakeGroupies(attr.GroupCutoffs, attr.GroupDescriptions); } return(column); }
public static IList <OLVColumn> GenerateColumns(Type type) { List <OLVColumn> list = new List <OLVColumn>(); foreach (PropertyInfo info in type.GetProperties()) { OLVColumnAttribute customAttribute = Attribute.GetCustomAttribute(info, typeof(OLVColumnAttribute)) as OLVColumnAttribute; if (customAttribute != null) { list.Add(MakeColumnFromAttribute(info.Name, customAttribute, info.CanWrite)); } } list.Sort((x, y) => x.DisplayIndex.CompareTo(y.DisplayIndex)); return(list); }
/// <summary> /// Generate a list of OLVColumns based on the attributes of the given type /// that have a OLVColumn attribute. /// </summary> /// <param name="type"></param> /// <returns>A collection of OLVColumns matching the attributes of Type that have OLVColumnAttributes.</returns> static public IList <OLVColumn> GenerateColumns(Type type) { List <OLVColumn> columns = new List <OLVColumn>(); // Iterate all public properties in the class and build columns from those that have // an OLVColumn attribute. foreach (PropertyInfo pinfo in type.GetProperties()) { OLVColumnAttribute attr = Attribute.GetCustomAttribute(pinfo, typeof(OLVColumnAttribute)) as OLVColumnAttribute; if (attr != null) { columns.Add(Generator.MakeColumnFromAttribute(pinfo.Name, attr, pinfo.CanWrite)); } } // How many columns have DisplayIndex specifically set? int countPositiveDisplayIndex = 0; foreach (OLVColumn col in columns) { if (col.DisplayIndex >= 0) { countPositiveDisplayIndex += 1; } } // Give columns that don't have a DisplayIndex an incremental index int columnIndex = countPositiveDisplayIndex; foreach (OLVColumn col in columns) { if (col.DisplayIndex < 0) { col.DisplayIndex = (columnIndex++); } } columns.Sort(delegate(OLVColumn x, OLVColumn y) { return(x.DisplayIndex.CompareTo(y.DisplayIndex)); }); return(columns); }
static public IList <OLVColumn> GenerateColumns(Type type) { List <OLVColumn> columns = new List <OLVColumn>(); // Iterate all public properties in the class and build columns from those that have // an OLVColumn attribute. foreach (PropertyInfo pinfo in type.GetProperties()) { OLVColumnAttribute attr = Attribute.GetCustomAttribute(pinfo, typeof(OLVColumnAttribute)) as OLVColumnAttribute; if (attr != null) { columns.Add(Generator.MakeColumnFromAttribute(pinfo.Name, attr, pinfo.CanWrite)); } } columns.Sort(delegate(OLVColumn x, OLVColumn y) { return(x.DisplayIndex.CompareTo(y.DisplayIndex)); }); return(columns); }
/// <summary> /// Create a column. /// </summary> /// <param name="aspectName"></param> /// <param name="title"></param> /// <param name="attr"></param> /// <returns></returns> protected virtual OLVColumn MakeColumn(string aspectName, string title, OLVColumnAttribute attr) { string columnTitle = (attr == null || String.IsNullOrEmpty(attr.Title)) ? title : attr.Title; return(new OLVColumn(columnTitle, aspectName)); }
/// <summary> /// Create a column with all the given information /// </summary> /// <param name="aspectName"></param> /// <param name="title"></param> /// <param name="editable"></param> /// <param name="propertyType"></param> /// <param name="attr"></param> /// <returns></returns> protected virtual OLVColumn MakeColumn(string aspectName, string title, bool editable, Type propertyType, OLVColumnAttribute attr) { OLVColumn column = this.MakeColumn(aspectName, title, attr); column.Name = (attr == null || String.IsNullOrEmpty(attr.Name)) ? aspectName : attr.Name; this.ConfigurePossibleBooleanColumn(column, propertyType); if (attr == null) { column.IsEditable = editable; column.Width = -1; // Auto size return(column); } column.AspectToStringFormat = attr.AspectToStringFormat; if (attr.IsCheckBoxesSet) { column.CheckBoxes = attr.CheckBoxes; } column.DisplayIndex = attr.DisplayIndex; column.FillsFreeSpace = attr.FillsFreeSpace; if (attr.IsFreeSpaceProportionSet) { column.FreeSpaceProportion = attr.FreeSpaceProportion; } column.GroupWithItemCountFormat = attr.GroupWithItemCountFormat; column.GroupWithItemCountSingularFormat = attr.GroupWithItemCountSingularFormat; column.Hyperlink = attr.Hyperlink; column.ImageAspectName = attr.ImageAspectName; column.IsEditable = attr.IsEditableSet ? attr.IsEditable : editable; column.IsTileViewColumn = attr.IsTileViewColumn; column.IsVisible = attr.IsVisible; column.MaximumWidth = attr.MaximumWidth; column.MinimumWidth = attr.MinimumWidth; column.Tag = attr.Tag; if (attr.IsTextAlignSet) { column.TextAlign = attr.TextAlign; } column.ToolTipText = attr.ToolTipText; if (attr.IsTriStateCheckBoxesSet) { column.TriStateCheckBoxes = attr.TriStateCheckBoxes; } column.UseInitialLetterForGroup = attr.UseInitialLetterForGroup; column.Width = attr.Width; if (attr.GroupCutoffs != null && attr.GroupDescriptions != null) { column.MakeGroupies(attr.GroupCutoffs, attr.GroupDescriptions); } return(column); }
/// <summary> /// Make a column from the given PropertyDescriptor /// </summary> /// <param name="pd"></param> /// <returns></returns> public virtual OLVColumn MakeColumnFromPropertyDescriptor(PropertyDescriptor pd) { OLVColumnAttribute attr = pd.Attributes[typeof(OLVColumnAttribute)] as OLVColumnAttribute; return(MakeColumn(pd.Name, DisplayNameToColumnTitle(pd.DisplayName), !pd.IsReadOnly, pd.PropertyType, attr)); }
/// <summary> /// Create a column from the given PropertyInfo and OLVColumn attribute /// </summary> /// <param name="pinfo"></param> /// <param name="attr"></param> /// <returns></returns> protected virtual OLVColumn MakeColumnFromAttribute(PropertyInfo pinfo, OLVColumnAttribute attr) { return(MakeColumn(pinfo.Name, DisplayNameToColumnTitle(pinfo.Name), pinfo.CanWrite, pinfo.PropertyType, attr)); }
/// <summary> /// Generate a list of OLVColumns based on the attributes of the given type /// If allProperties to true, all public properties will have a matching column generated. /// If allProperties is false, only properties that have a OLVColumn attribute will have a column generated. /// </summary> /// <param name="type"></param> /// <param name="allProperties">Will columns be generated for properties that are not marked with [OLVColumn].</param> /// <returns>A collection of OLVColumns matching the attributes of Type that have OLVColumnAttributes.</returns> public virtual IList <OLVColumn> GenerateColumns(Type type, bool allProperties) { List <OLVColumn> columns = new List <OLVColumn>(); // Sanity if (type == null) { return(columns); } // Iterate all public properties in the class and build columns from those that have // an OLVColumn attribute and that are not ignored. foreach (PropertyInfo pinfo in type.GetProperties()) { if (Attribute.GetCustomAttribute(pinfo, typeof(OLVIgnoreAttribute)) != null) { continue; } OLVColumnAttribute attr = Attribute.GetCustomAttribute(pinfo, typeof(OLVColumnAttribute)) as OLVColumnAttribute; if (attr == null) { if (allProperties) { columns.Add(this.MakeColumnFromPropertyInfo(pinfo)); } } else { columns.Add(this.MakeColumnFromAttribute(pinfo, attr)); } } // How many columns have DisplayIndex specifically set? int countPositiveDisplayIndex = 0; foreach (OLVColumn col in columns) { if (col.DisplayIndex >= 0) { countPositiveDisplayIndex += 1; } } // Give columns that don't have a DisplayIndex an incremental index int columnIndex = countPositiveDisplayIndex; foreach (OLVColumn col in columns) { if (col.DisplayIndex < 0) { col.DisplayIndex = (columnIndex++); } } columns.Sort(delegate(OLVColumn x, OLVColumn y) { return(x.DisplayIndex.CompareTo(y.DisplayIndex)); }); return(columns); }
private static OLVColumn MakeColumnFromAttribute(string aspectName, OLVColumnAttribute attr, bool editable) { string title = String.IsNullOrEmpty(attr.Title) ? aspectName : attr.Title; OLVColumn column = new OLVColumn(title, aspectName); column.AspectToStringFormat = attr.AspectToStringFormat; column.CheckBoxes = attr.CheckBoxes; column.DisplayIndex = attr.DisplayIndex; column.FillsFreeSpace = attr.FillsFreeSpace; if (attr.FreeSpaceProportion.HasValue) column.FreeSpaceProportion = attr.FreeSpaceProportion.Value; column.GroupWithItemCountFormat = attr.GroupWithItemCountFormat; column.GroupWithItemCountSingularFormat = attr.GroupWithItemCountSingularFormat; column.Hyperlink = attr.Hyperlink; column.ImageAspectName = attr.ImageAspectName; if (attr.IsEditableSet) column.IsEditable = attr.IsEditable; else column.IsEditable = editable; column.IsTileViewColumn = attr.IsTileViewColumn; column.IsVisible = attr.IsVisible; column.MaximumWidth = attr.MaximumWidth; column.MinimumWidth = attr.MinimumWidth; column.Name = String.IsNullOrEmpty(attr.Name) ? aspectName : attr.Name; column.Tag = attr.Tag; column.TextAlign = attr.TextAlign; column.ToolTipText = attr.ToolTipText; column.TriStateCheckBoxes = attr.TriStateCheckBoxes; column.UseInitialLetterForGroup = attr.UseInitialLetterForGroup; column.Width = attr.Width; if (attr.GroupCutoffs != null && attr.GroupDescriptions != null) column.MakeGroupies(attr.GroupCutoffs, attr.GroupDescriptions); return column; }
/// <summary> /// Create a column. /// </summary> /// <param name="aspectName"></param> /// <param name="title"></param> /// <param name="attr"></param> /// <returns></returns> protected virtual OLVColumn MakeColumn(string aspectName, string title, OLVColumnAttribute attr) { string columnTitle = (attr == null || String.IsNullOrEmpty(attr.Title)) ? title : attr.Title; return new OLVColumn(columnTitle, aspectName); }
/// <summary> /// Create a column with all the given information /// </summary> /// <param name="aspectName"></param> /// <param name="title"></param> /// <param name="editable"></param> /// <param name="propertyType"></param> /// <param name="attr"></param> /// <returns></returns> protected virtual OLVColumn MakeColumn(string aspectName, string title, bool editable, Type propertyType, OLVColumnAttribute attr) { OLVColumn column = this.MakeColumn(aspectName, title, attr); column.Name = (attr == null || String.IsNullOrEmpty(attr.Name)) ? aspectName : attr.Name; this.ConfigurePossibleBooleanColumn(column, propertyType); if (attr == null) { column.IsEditable = editable; return column; } column.AspectToStringFormat = attr.AspectToStringFormat; if (attr.IsCheckBoxesSet) column.CheckBoxes = attr.CheckBoxes; column.DisplayIndex = attr.DisplayIndex; column.FillsFreeSpace = attr.FillsFreeSpace; if (attr.IsFreeSpaceProportionSet) column.FreeSpaceProportion = attr.FreeSpaceProportion; column.GroupWithItemCountFormat = attr.GroupWithItemCountFormat; column.GroupWithItemCountSingularFormat = attr.GroupWithItemCountSingularFormat; column.Hyperlink = attr.Hyperlink; column.ImageAspectName = attr.ImageAspectName; column.IsEditable = attr.IsEditableSet ? attr.IsEditable : editable; column.IsTileViewColumn = attr.IsTileViewColumn; column.IsVisible = attr.IsVisible; column.MaximumWidth = attr.MaximumWidth; column.MinimumWidth = attr.MinimumWidth; column.Tag = attr.Tag; if (attr.IsTextAlignSet) column.TextAlign = attr.TextAlign; column.ToolTipText = attr.ToolTipText; if (attr.IsTriStateCheckBoxesSet) column.TriStateCheckBoxes = attr.TriStateCheckBoxes; column.UseInitialLetterForGroup = attr.UseInitialLetterForGroup; column.Width = attr.Width; if (attr.GroupCutoffs != null && attr.GroupDescriptions != null) column.MakeGroupies(attr.GroupCutoffs, attr.GroupDescriptions); return column; }
/// <summary> /// Create a column from the given PropertyInfo and OLVColumn attribute /// </summary> /// <param name="pinfo"></param> /// <param name="attr"></param> /// <returns></returns> protected virtual OLVColumn MakeColumnFromAttribute(PropertyInfo pinfo, OLVColumnAttribute attr) { return MakeColumn(pinfo.Name, DisplayNameToColumnTitle(pinfo.Name), pinfo.CanWrite, pinfo.PropertyType, attr); }
/// <summary> /// Create a column from the given FieldInfo and OLVColumn attribute /// </summary> /// <param name="pinfo"></param> /// <param name="attr"></param> /// <returns></returns> protected virtual OLVColumn MakeColumnFromAttribute(FieldInfo pinfo, OLVColumnAttribute attr) { return(MakeColumn(pinfo.Name, DisplayNameToColumnTitle(pinfo.Name), false, pinfo.GetType(), attr)); }
/// <summary> /// Create a column from the given FieldInfo and OLVColumn attribute /// </summary> /// <param name="pinfo"></param> /// <param name="attr"></param> /// <returns></returns> protected virtual OLVColumn MakeColumnFromAttribute(FieldInfo finfo, OLVColumnAttribute attr) { return MakeColumn(finfo.Name, DisplayNameToColumnTitle(finfo.Name), false, finfo.GetType(), attr); }