Click here to Skip to main content
15,891,136 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;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace Puma.Controls.PropertyGrid
{
	public class PropertyGrid : System.Windows.Forms.PropertyGrid
	{
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		//private readonly GridItemTextBox _gridItemTextBox;

		public PropertyGrid()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitializeComponent call

            this.PropertySort = System.Windows.Forms.PropertySort.NoSort;

			ContextMenu = new ContextMenu.ContextMenu(this);

			//this.PropertySort = System.Windows.Forms.PropertySort.NoSort;

			//_gridItemTextBox = new GridItemTextBox(this);
		}

        private IPropertyGridItem _IPropertyGridItem;

        public IPropertyGridItem PropertyGridItemRoot { get { return _IPropertyGridItem; } }

        private bool _firstItemsAsCategories = false;

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				//_gridItemTextBox.Dispose();

				//ContextMenu.Dispose();

				if(components != null)
				{
					components.Dispose();
				}
			}

			base.Dispose( disposing );

		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{

		}

		#endregion

        public void SetContent(IPropertyGridItem IPropertyGridItem)
		{
            IPropertyGridItemRootEx pgie = new PropertyGridItemRootExImpl(IPropertyGridItem, this);

            SetContent(pgie);
		}

        public void SetContent(IPropertyGridItemRootEx IPropertyGridItemRootEx)
        {
            _IPropertyGridItem = IPropertyGridItemRootEx.BaseItem;

            this.SelectedObject = new PropertyGridItem(IPropertyGridItemRootEx);
        }


        /*
         * !!!http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=117133!!!
         * http://66.129.67.100/247reference/msgs/58/292060.aspx
         * http://forums.microsoft.com/msdn/showpost.aspx?postid=67345&siteid=1
         * http://forums.microsoft.com/msdn/showpost.aspx?postid=9739&siteid=1
         * 
         */

        public bool FirstItemsAsCategories
        {
            get { return _firstItemsAsCategories; }

            set { _firstItemsAsCategories = value; }
        }
		
		internal IPropertyGridItemEx SelectedPropertyGridItemEx { get {return SelectedGridItem.PropertyDescriptor == null ? null : ((Puma.Controls.PropertyGrid.PropertyDescriptor)SelectedGridItem.PropertyDescriptor).IPropertyGridItemEx;} } 

        /*
		internal System.Windows.Forms.TextBox ActiveGridItemTextBox
		{
			get
			{
				System.Diagnostics.Debug.Assert(ActiveControl.Controls != null);

				foreach (Control ctl in ActiveControl.Controls)
				{
					if (ctl is TextBox) return (TextBox)ctl;
				}

				System.Diagnostics.Debug.Assert(false);

				return null;
			}
		}
		*/

	}
}

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