Click here to Skip to main content
15,892,072 members
Articles / Programming Languages / C#

PropertyGrid

Rate me:
Please Sign up or sign in to vote.
3.22/5 (3 votes)
3 Nov 20069 min read 52.2K   1.3K   30  
A control which provides a convenient way to display data in a property grid.
 
using System;

namespace Puma.Collections
{
	public class ShredCollector : IShredCollector
	{
		public ShredCollector()
		{
		}

		private Puma.Collections.NameObjectList _nameObjectList = new NameObjectList();

        protected virtual IShred OnShredCreated(string Name, ShredCollector ShredCollector) { return new Shred(Name, ShredCollector); }

		#region IShredCollector Members

		public IShred AddShred(string Name)
		{
			// TODO:  Add ShredCollector.CreateShred implementation
            if (IsShredExist(Name)) throw new Puma.Collections.Exception("Shred with the same name already exist");

            IShred shred = OnShredCreated(Name, this);

			_nameObjectList.Add(Name, shred);

			return shred;
		}

        public IShred AddItem(string ShredName, object Item)
        { 
            IShred shred;

            if (!IsShredExist(ShredName))
            {
                shred = AddShred(ShredName);
            }
            else
            {
                shred = GetShred(ShredName);
            }

            shred.Insert(-1, Item);

            return shred;
        }

		#endregion

		#region IShredCollectorReadOnly Members

		public IShred GetShred(string Name)
		{
			// TODO:  Add ShredCollector.GetShred implementation
			return (IShred)_nameObjectList[Name];
		}

        public IShred GetShred(int Index)
        {
            // TODO:  Add ShredCollector.GetShred implementation
            int i = 0;

            foreach (IShred shred in this)
            {
                if (i == Index) return shred;

                i++;
            }

            return null;
        }

		public bool IsShredExist(string Name)
		{
				// TODO:  Add ShredCollector.IsShredExist getter implementation
				return _nameObjectList.IsNameExist(Name);

		}

		public int Count
		{
			get
			{
				// TODO:  Add ShredCollector.Count getter implementation
				return 	_nameObjectList.Count;
			}
		}

		public System.Collections.IEnumerable GetAllContainedItems()
		{
			System.Collections.ArrayList al = new System.Collections.ArrayList();

			foreach(IShred shred in _nameObjectList.Values)
			{
				al.AddRange(shred.GetCollection());
			}

			return al;
		}

		#endregion

		#region IEnumerable Members

		public System.Collections.IEnumerator GetEnumerator()
		{
			// TODO:  Add ShredCollector.GetEnumerator implementation
			return _nameObjectList.Values.GetEnumerator();
		}

		#endregion

        #region Neighbour Shreds

        public Shred GetPerviousShred(string ShredName)
        {
            return GetNeighbourShred(ShredName, true);
        }

        public Shred GetNextShred(string ShredName)
        {
            return GetNeighbourShred(ShredName, false);
        }

        private Shred GetNeighbourShred(string ShredName, bool fPerv)
        {
            Shred pervShred = null;

            bool fEncountred = false;

            foreach (Shred shred in this)
            {
                if (shred.Name == ShredName)
                {
                    if (fPerv)
                    {
                        return pervShred == null ? null : pervShred;
                    }
                    else
                    {
                        fEncountred = true;
                    }
                }
                else
                {
                    pervShred = shred;

                    if (!fPerv && fEncountred) return shred;
                }
            }

            return null;
        }

        #endregion

	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


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

Comments and Discussions