Click here to Skip to main content
15,884,353 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.5K   7.6K   110  
Docking windows container, extended listview, extended property editor.
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;

namespace dwf.tool
{
    public class PColumnMap : LayoutMap
    {
        [NonSerialized()]
        protected PListInfo _info;
        
        public PColumnMap()
        {
            base.Items.ListChanged += ItemsListChanged;
        }
        
        ~PColumnMap()
        {
            base.Items.ListChanged -= ItemsListChanged;
        }

        private void ItemsListChanged(object sender, ListChangedEventArgs e)
        {
            if (((PColumnMap)TopMap).Info != null)
                ((PColumnMap)TopMap).Info.OnBoundChanged(EventArgs.Empty);
        }

        public PColumnMap(PListInfo info)
        {
            this._info = info;
        }

        public PListInfo Info
        {
            get { return _info; }
            set { _info = value; }
        }

        public override float Scale
        {
            get { return _info == null ? base.Scale : _info.Scale; }
            set { _info.Scale = value; }
        }

        public RectangleF GetBound(float max, CalcWidthDelegate wd, CalcHeightDelegate hd)
        {
            return LayoutMapTool.GetBound(this, new SizeF(max, 0), wd, hd);
        }

        public RectangleF GetBound(ILayoutMapItem column, RectangleF temp, CalcWidthDelegate wd, CalcHeightDelegate hd)
        {
            return LayoutMapTool.GetBound(this, column, temp, wd, hd);
        }

        //moving column to some side of other column
        public void Move(ILayoutMapItem moved, ILayoutMapItem destination, LayoutAlignType anch, bool builGroup)
        {
            LayoutMapTool.Move(moved, destination, anch, builGroup);
            ((PColumnMap)TopMap).Info.OnBoundChanged(EventArgs.Empty);
        }

        public List<PColumn> GetDisplayed(RectangleF clip, RectangleF temp, CalcWidthDelegate wd, CalcHeightDelegate hd)
        {
            List<ILayoutMapItem> cols = LayoutMapTool.GetItems(this);
            List<PColumn> buf = new List<PColumn>();

            foreach (ILayoutMapItem col in cols)
            {
                if (col.Visible)
                {
                    RectangleF rec = GetBound(col, temp, wd, hd);
                    rec.X += _info.HeaderWidth + 1;// leftPadding
                    rec.Width -= 1;
                    if (rec.Right > clip.Left && rec.Left < clip.Right)
                        buf.Add((PColumn)col);
                }
            }
            return buf;
        }

        public void _Clear()
        {
            items.Clear();
        }

        public void Clear()
        {
            _Clear();
        }

        public void Replace(ILayoutMapItem oldColumn, ILayoutMapItem newColumn)
        {
            LayoutMapTool.Replace(oldColumn, newColumn);
        }

        public PColumn Add(string property, float width = 100, int row = 0, int col = 0)
        {
            PColumn column = new PColumn();
            column.Name = property;
            column.Width = width;
            column.Row = row;
            column.Col = col;
            Add(column);
            return column;
        }

        public void Add(ILayoutMapItem column)
        {
            LayoutMapTool.Add(this, column);
        }

        public void Insert(ILayoutMapItem column, bool inserRow)
        {
            LayoutMapTool.Insert(this, column, inserRow);
        }

        public void InsertAfter(ILayoutMapItem column, ILayoutMapItem excolumn)
        {
            column.Row = excolumn.Row;
            column.Col = excolumn.Col + 1;
            Insert(column, false);
        }

        public bool Remove(ILayoutMapItem column)
        {
            return LayoutMapTool.Remove(column);
        }

        public void Reset()
        {
            LayoutMapTool.Reset(this);
        }

        public List<ILayoutMapItem> GetVisible()
        {
            List<ILayoutMapItem> list = LayoutMapTool.GetVisibleItems(this);
            return list;
        }

        public void InsertWith(PColumn newvalue, PColumn oldvalue, bool p)
        {
            throw new NotImplementedException();
        }
    }

}

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