Example #1
0
        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);

            column.AspectToStringFormat             = attr.AspectToStringFormat;
            column.CheckBoxes                       = attr.CheckBoxes;
            column.DisplayIndex                     = attr.DisplayIndex;
            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.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);
        }
Example #2
0
        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);
        }