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; }
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> /// 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)); } } columns.Sort(delegate(OLVColumn x, OLVColumn y) { return(x.DisplayIndex.CompareTo(y.DisplayIndex)); }); return(columns); }