Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Windows Forms » Downloads
 
Add your own
alternative version

Unleash PropertyGrid with Dynamic Properties and Globalization

, 29 Jan 2004
The article presents a way to enhance the use of the PropertyGid control with dynamic properties and globalization
using System;
using CustomControls.BaseClasses;
using CustomControls.HelperClasses;
using System.Windows.Forms;
using System.ComponentModel;

namespace CustomControls.Win32Controls
{
	
	public class DropDownBool:DropDownListBox
	{
		
		private DropDownBool.ListItem TrueItem = new DropDownBool.ListItem("True");
		private DropDownBool.ListItem FalseItem = new DropDownBool.ListItem("False");
		private bool _Value= true;
		public event EventHandler ValueChanged;
		
		[DefaultValue(typeof(string),"True")]
		public string TrueValueString
		{
			get{return TrueItem.Text;}
			set
			{
				if(value != TrueItem.Text)
				{
					TrueItem.Text= value;
                    
				}
			}
		}

		[DefaultValue(typeof(string),"False")]
		public string FalseValueString
		{
			get{return FalseItem.Text;}
			set
			{
				if(value != FalseItem.Text)
				{
					FalseItem.Text= value;
					
				}
			}
		}

		[Browsable(false)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public override ComboBoxStyle DropDownStyle
		{
			get{return ComboBoxStyle.DropDownList;}
		}

		[DefaultValue(typeof(bool),"True")]
		public bool Value
		{
			get{return _Value;}
			set
			{
				if(value!=_Value)
				{
					_Value=value;
					OnValueChanged(new EventArgs());
					Invalidate();
				}
			}
		}


		public DropDownBool()
		{
			this.DropDownStyle=ComboBoxStyle.DropDownList;
			this.List.Items.Add(TrueItem);	
			this.List.Items.Add(FalseItem);	

			this.List.SelectedIndexChanged+=new EventHandler(List_SelectedIndexChanged);

		}


		protected virtual void OnValueChanged(System.EventArgs e)
		{
			
			if(Value)
			{
				List.SelectedItem=TrueItem;
				this.Text=TrueValueString;
			}
			else
			{
				List.SelectedItem=FalseItem;
				this.Text=FalseValueString;
			}

			if(ValueChanged!= null)	{ValueChanged(this,e);}
		}

		private void List_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(List.SelectedItem==TrueItem){Value=true;}
			else{Value=false;}
		}	

		

		protected override void OnKeyDown(KeyEventArgs e)
		{
			base.OnKeyDown(e);
			if(e.KeyData==Keys.Space){Value=!Value;}
		}

		internal class ListItem:object
		{
			private string _Text=string.Empty;
			
			public string Text
			{
				get{return _Text; }
				set{_Text= value;}
			}

			public ListItem()
			{}

			public ListItem(string Text)
			{
				_Text= Text;
			}

			public override string ToString()
			{
				return _Text;
			}
		}
	}
}

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)

Share

About the Author

Daniel Zaharia
Web Developer
Romania Romania
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 30 Jan 2004
Article Copyright 2004 by Daniel Zaharia
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid