Click here to Skip to main content
15,891,473 members
Articles / Desktop Programming / Windows Forms

Controls Library: Extended ListView with Column Mapping

Rate me:
Please Sign up or sign in to vote.
4.86/5 (29 votes)
27 Mar 2014CPOL5 min read 82.9K   7.6K   110  
Docking windows container, extended listview, extended property editor.
using System;
using System.ComponentModel;

namespace dwf.tool
{
    public enum CollectedType
    {
        None,
        Sum,
        Min,
        Max,
        Avg,
        Custom
    }

    public class PColumn : LayoutMapItem, IPCell, IComparable<ILayoutMapItem>, IComparable, IDisposable
    {
        protected PCellStyle style;
        //accessor of the property
        [NonSerialized()]
        protected ReflectionAccessor _accessor;
        //edit control
        [NonSerialized()]
        protected IPCellEditor _control;
        //for compaund columns property 
        [NonSerialized()]
        protected IPCell _owner;
        //implement IColumn
        [NonSerialized()]
        private PColumnList _columns;
        [NonSerialized()]
        protected string _header;
        [DefaultValue(CollectedType.None)]
        protected CollectedType collect = CollectedType.None;
        [DefaultValue(false)]
        protected bool readOnly = false;
        [DefaultValue(true)]
        protected bool view = true;
        [DefaultValue(true)]
        protected bool editable = true;
        [DefaultValue(false)]
        protected bool cstyle = false;
        protected string owner = null;
        protected string format = null;

        public PColumn()
        {
        }

        [Browsable(false)]
        public PColumnList Columns
        {
            get
            {
                if (_columns == null)
                    _columns = new PColumnList();
                return _columns;
            }
        }

        public string Format
        {
            get { return format; }
            set
            {
                if (format != value)
                {
                    format = value;
                    if (_control != null)
                        _control.Format = value;
                }
            }
        }

        [Browsable(false)]
        public IPCell Owner
        {
            get
            {
                if (_owner == null && owner != null && Info != null)
                    _owner = Info.Columns[owner] as IPCell;
                return _owner;
            }
            set
            {
                if (_owner == value)
                    return;
                _owner = value;
                owner = value == null ? null : value.Name;
            }
        }

        public bool CustomeStyle
        {
            get { return cstyle; }
            set
            {
                if (cstyle == value)
                    return;
                cstyle = value;
                if (!cstyle)
                    style = null;

            }
        }

        [Browsable(false)]
        public PListInfo Info
        {
            get
            {
                return map == null || ((PColumnMap)map).TopMap == null ? null : ((PColumnMap)((PColumnMap)map).TopMap).Info;
            }
        }

        public PCellStyle Style
        {
            get
            {
                if (cstyle && style == null)
                {
                    if (Info != null)
                        style = (PCellStyle)Info.StyleCell.Clone();
                    else
                        style = new PCellStyle();
                }
                else if (!cstyle)
                    return Info.StyleCell;
                return style;
            }
            set { style = value; }
        }

        public CollectedType Collect
        {
            get { return collect; }
            set { collect = value; }
        }

        public ReflectionAccessor Accessor
        {
            get { return _accessor; }
            set { _accessor = value; }
        }

        public IPCellEditor Editor
        {
            get { return _control; }
            set
            {
                if (_control != value)
                {
                    _control = value;
                    if (_control != null)
                        format = _control.Format;
                }
            }
        }

        public string Header
        {
            get { return _header; }
            set { _header = value; }
        }

        public bool ReadOnly
        {
            get { return readOnly; }
            set
            {
                if (readOnly != value)
                {
                    readOnly = value;
                }
            }
        }

        [Browsable(false)]
        public bool Editable
        {
            get { return this.editable; }
            set { editable = value; }
        }

        [Browsable(false)]
        public bool View
        {
            get { return view; }
            set
            {
                if (view = value)
                    return;
                view = value;
                visible = view;
            }
        }

        public int CompareTo(ILayoutMapItem obj)
        {
            return base.CompareTo(obj);
        }

        public void Dispose()
        {
            if (style != null)
                style.Dispose();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Kazakstan Kazakstan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions