Introduction
This editor displays a dropdown control holding a CheckedListBox
with all the values of an enumeration.
Using the FlagsEditor
You just have to put the Editor
attributes on an enumeration to link it with the FlagsEditor
. A Description
attribute can also be added to each value. It will be shown as a tooltip on the CheckedListBox
items.
Here is a sample.
[Flags, Editor(typeof(STUP.ComponentModel.Design.FlagsEditor), typeof(System.Drawing.Design.UITypeEditor))]public enum EnumerationTest{ [Description("Description for the first tested value.")] firstValue = 1, [Description("Description for the second tested value.")] secondValue = 2, [Description("Description for the third tested value.")] thirdValue = 4}
How does it work ?
The Editor
is just one class that inherits UITypeEditor
. The behavior of Editor
is controlled by two functions.
GetEditStyle
This function is used for controlling the appearance of the small button in the property grid. In this sample a dropdown arrow will be shown.
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) { return UITypeEditorEditStyle.DropDown;}
EditValue
This function is called when the user clicks on the small button.
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (context != null && context.Instance != null && provider != null) { // Get an instance of the IWindowsFormsEditorService. edSvc = (IWindowsFormsEditorService)provider.GetService (typeof(IWindowsFormsEditorService)); if (edSvc != null) { // Create a CheckedListBox clb = new CheckedListBox(); ... // Show our CheckedListbox as a DropDownControl. // This methods returns only when // the dropdowncontrol is closed edSvc.DropDownControl(clb); // return the right enum value // corresponding to the result return ... } } return value;}
The DropDownControl
can be closed by calling the edSvc.CloseDropDown()
function.
For a complete example, just download the source file.
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
'개발 관련 글' 카테고리의 다른 글
[프로그램] 기업에서까지 완전 무료 프로그램 - 진정한 FREE!! (0) | 2009.04.28 |
---|---|
C# List View v1.3 (0) | 2009.04.21 |
2008/12/04 자동 업데이터 (HAU, Http Auto Updater) (0) | 2009.04.15 |
Smart Client (Web-embedded) 보안 (0) | 2009.04.15 |
[Java] 바이오리듬 구하는 소스 (0) | 2009.03.23 |