|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionThis article helps in understanding the basic fundamentals of a .NET property grid. Developers who dont have first hand knowledge about property grid can use this article to get a basic idea of how and where a property grid can be used. BackgroundProperty grid can be primarily used for displaying properties of a buisness object. This contains flexibilities like adding dropdownlists , boolean properties to the grid and hence expose the different types of operations that the end-user can perform on a property grid Using the codeThe demo contains a form containing propoerty grid displaying the properties of a customer class. The customer class has properties like Customer Class , customer ID , type etc... I have inherited the UITypeEditor class from System.Drawing.Design. This class can be used to populate other types controls mainly drop down lists in a property grid. //Using System.Drawing.Design; //public class Customer : UITypeEditorDeclare a ListBox Control and a windows editor service to control the functionalities of the Property grid ListBox dropdownlist = new ListBox();
public int CustomerID { get{return m_CustomerID;} set{m_CustomerID = value;} } The end -user will not be able to type string values in the Customer ID field.The Property grid will throw an exception as "Property value Invalid".Aint this cool??? On the other hand the negative aspect of this validation is that this is a System thrown exception. So it is not advisable to ovveride the exception to display a custom message as this might cause malfunctioning of the .NET Property Grid itself. Let us now explore the other possibilities of the property grid To display a property as a dropdown list , we need to use the UITypeEditor class. Consider the following example public static string[] dropdownlist; public string[] typeList = {"Overseas","Localized",""} [Editor(typeof(Customer),typeof(UITypeEditor))] public string CustomerType { get{dropdownlist = typeList;} set{m_CustomerType = value;}return value; } On setting the Editor attribute to a particular property the display style automatically changes on runtime.Now lets see some other useful attributes that can be commonly used for a grid. [CategoryAttribute("Customer Details"),Browsable(false)] public int CustomerID { get{return m_CustomerID;} set{m_CustomerID = value;} }
Methods in UITypeEditor public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptionContext context) { return UITypeEditorEditStyle.DropDown } The above method sets the UITypeEditor to a drop down. The above method assigns the specific string array to the dropdownlist. The Windows service helps to return the list through the UIType Editor class Points of InterestManipulation of values in the property grid can be done at the object level. This helps the developer to just pass the object instead of passing individual values for updation in database , saving and other db operations.For example if you using NHibernate to talk with a Firebird database then the customer object can be passed to the update method of NHibernate.
|
||||||||||||||||||||||