Click here to Skip to main content
13,148,173 members (33,436 online)
Click here to Skip to main content
Articles » Languages » C# » Windows Forms » Downloads

Stats

104K views
4.4K downloads
87 bookmarked
Posted 29 Jan 2004

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 System.Windows.Forms;
using System.ComponentModel;
using CustomControls.BaseClasses;
using CustomControls.HelperClasses;


using System.Drawing.Design;

namespace CustomControls.Win32Controls
{
	public class DropDownListBoxButton:DropDownButtonBase 
	{
		public delegate void ItemSelectedEventHandler(object sender, ItemSelectedEventArgs e);
		[Category("Action")]
		public event ItemSelectedEventHandler ItemSelected;

		private ListBox _List= new ListBox();
		private int _MaxDropDawnItems=8;
		private int _MinListWidth=140;



		protected override System.Windows.Forms.Control HostedControl
		{
			get
			{
				return _List;
			}
		}

		[Category("Behavior")]
		[DefaultValue(typeof(System.Int32),"140")]
		public int MinListWidth
		{
			get{return _MinListWidth;}
			set{_MinListWidth= value;}
		}



		[Category("Behavior")]
		[DefaultValue(typeof(System.Int32),"8")]
		public int MaxDropDownItems
		{
			get{return _MaxDropDawnItems;}
			set{_MaxDropDawnItems=value;}
		}


		[Browsable(false)]
		public ListBox List
		{
			get{return _List;}
		}

		public DropDownListBoxButton()
		{
			_List.BorderStyle=System.Windows.Forms.BorderStyle.None;
			_List.MouseUp+= new MouseEventHandler(List_MouseUp);
		}



		protected override void OnDropDown(EventArgs e)
		{
			base.OnDropDown(e);

			if (Text!=string.Empty)	{_List.SelectedIndex=_List.FindString(Text);}
			else{_List.SelectedIndex=-1;}

			int lHeight,lWidth;
			lHeight=Math.Max(List.ItemHeight,Math.Min(MaxDropDownItems, List.Items.Count)*List.ItemHeight);
			lWidth=Math.Max(this.Width+20,MinListWidth);
			dropDownForm.Size= new System.Drawing.Size(lWidth,lHeight+4);
			
		}


				
		private void List_MouseUp(object sender , MouseEventArgs e)
		{
			State=Enumerations.ButtonState.Normal;
			OnItemSelected(new ItemSelectedEventArgs(List.SelectedItem,List.SelectedIndex));
		}

	
		

		protected override void OnNextItem()
		{
			if(_List.SelectedIndex<_List.Items.Count-1)
			{
				_List.SelectedIndex+=1;
			}
		}

		protected override void OnPrevItem()
		{
			if(_List.SelectedIndex>0)
			{
				_List.SelectedIndex-=1;
			}
		}

	


		protected override void OnSelectItem(bool DefaultValue)
		{
			if(DefaultValue)
			{
				if(List.Items.Count>0)
				{
					OnItemSelected(new ItemSelectedEventArgs(List.Items[0],0));
				}
				else
				{
					OnItemSelected(new ItemSelectedEventArgs(null,-1));
				}
			}
			else
			{
				OnItemSelected(new ItemSelectedEventArgs(_List.SelectedItem,_List.SelectedIndex));
			}
		}



		protected virtual void OnItemSelected(ItemSelectedEventArgs e)
		{
			if (ItemSelected!=null)
			{
				ItemSelected(this,e);
			}
		}

		

	}
}

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

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170924.2 | Last Updated 30 Jan 2004
Article Copyright 2004 by Daniel Zaharia
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid